From 9f03682258d949b3b6ddd4fedec93977dedbadde Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Thu, 29 May 2014 13:34:38 +0200
Subject: [PATCH 001/751] Enderman attacks a player if he's looking at him.
---
src/Mobs/Enderman.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++
src/Mobs/Enderman.h | 1 +
2 files changed, 91 insertions(+)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index becc99a86..bd5ed85f1 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -2,6 +2,66 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Enderman.h"
+#include "../Entities/Player.h"
+
+
+
+
+///////////////////////////////////////////////////////////////////////////
+// cPlayerLookCheck
+class cPlayerLookCheck :
+ public cPlayerListCallback
+{
+public:
+ cPlayerLookCheck(Vector3d a_EndermanPos) :
+ m_EndermanPos(a_EndermanPos),
+ m_Player(NULL)
+ {
+ }
+
+ virtual bool Item(cPlayer * a_Player) override
+ {
+ // Don't check players who are in creative gamemode.
+ if (a_Player->IsGameModeCreative())
+ {
+ return false;
+ }
+
+ Vector3d Direction = m_EndermanPos - a_Player->GetPosition();
+
+ // Don't check players who are more then 64 blocks away.
+ if (Direction.SqrLength() > 64)
+ {
+ return false;
+ }
+
+ // Don't check if the player has a pumpkin on his head.
+ if (a_Player->GetEquippedHelmet().m_ItemType == E_BLOCK_PUMPKIN)
+ {
+ return false;
+ }
+
+ Direction.Normalize();
+
+ Vector3d LookVector = a_Player->GetLookVector();
+ LookVector.Normalize();
+
+ if ((Direction - LookVector).SqrLength() > 0.02)
+ {
+ return false;
+ }
+
+ // TODO: Don't attack the player if there is a wall between the player and the enderman.
+ m_Player = a_Player;
+ return true;
+ }
+
+ cPlayer * GetPlayer(void) const {return m_Player;}
+ bool HasFoundPlayer(void) const {return (m_Player != NULL);}
+protected:
+ cPlayer * m_Player;
+ Vector3d m_EndermanPos;
+} ;
@@ -32,3 +92,33 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
+void cEnderman::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ super::Tick(a_Dt, a_Chunk);
+
+ if (m_Target != NULL)
+ {
+ return;
+ }
+
+ cPlayerLookCheck Callback(GetPosition());
+ if (!m_World->ForEachPlayer(Callback))
+ {
+ return;
+ }
+
+ if (!Callback.HasFoundPlayer())
+ {
+ return;
+ }
+
+ m_bIsScreaming = true;
+ m_Target = Callback.GetPlayer();
+
+ m_World->BroadcastEntityMetadata(*this);
+}
+
+
+
+
+
diff --git a/src/Mobs/Enderman.h b/src/Mobs/Enderman.h
index 32e40e70b..be6e7bdf4 100644
--- a/src/Mobs/Enderman.h
+++ b/src/Mobs/Enderman.h
@@ -18,6 +18,7 @@ public:
CLASS_PROTODEF(cEnderman);
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
bool IsScreaming(void) const {return m_bIsScreaming; }
BLOCKTYPE GetCarriedBlock(void) const {return CarriedBlock; }
From 806130a967685b0708b51afc576df09d70d47d79 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Thu, 29 May 2014 14:00:12 +0200
Subject: [PATCH 002/751] Swapped m_Player and m_EndermanPos
---
src/Mobs/Enderman.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index bd5ed85f1..40782d0b0 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -14,8 +14,8 @@ class cPlayerLookCheck :
{
public:
cPlayerLookCheck(Vector3d a_EndermanPos) :
- m_EndermanPos(a_EndermanPos),
- m_Player(NULL)
+ m_Player(NULL),
+ m_EndermanPos(a_EndermanPos)
{
}
From 5d4f70a7a52e986343bddde2104f07c797c574c9 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Wed, 4 Jun 2014 09:19:55 +0100
Subject: [PATCH 003/751] Improved Enderman code
---
src/Mobs/Enderman.cpp | 45 ++++++++++++++++++++++++++++++-------------
src/Mobs/Enderman.h | 3 ++-
2 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 40782d0b0..416b541ed 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -3,6 +3,7 @@
#include "Enderman.h"
#include "../Entities/Player.h"
+#include "../Tracer.h"
@@ -51,13 +52,19 @@ public:
return false;
}
- // TODO: Don't attack the player if there is a wall between the player and the enderman.
+ cTracer LineOfSight(a_Player->GetWorld());
+ if (LineOfSight.Trace(m_EndermanPos, Direction, (int)Direction.Length()))
+ {
+ // No direct line of sight
+ return false;
+ }
+
m_Player = a_Player;
return true;
}
- cPlayer * GetPlayer(void) const {return m_Player;}
- bool HasFoundPlayer(void) const {return (m_Player != NULL);}
+ cPlayer * GetPlayer(void) const { return m_Player; }
+
protected:
cPlayer * m_Player;
Vector3d m_EndermanPos;
@@ -92,33 +99,45 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-void cEnderman::Tick(float a_Dt, cChunk & a_Chunk)
-{
- super::Tick(a_Dt, a_Chunk);
-
+void cEnderman::CheckEventSeePlayer()
+{
if (m_Target != NULL)
{
return;
}
cPlayerLookCheck Callback(GetPosition());
- if (!m_World->ForEachPlayer(Callback))
+ if (m_World->ForEachPlayer(Callback))
{
return;
}
+
+ ASSERT(Callback.GetPlayer() != NULL);
- if (!Callback.HasFoundPlayer())
+ int CX, CZ;
+ cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, CX, CZ);
+ if (!GetWorld()->IsChunkLighted(CX, CZ))
{
+ GetWorld()->QueueLightChunk(CX, CZ);
return;
}
- m_bIsScreaming = true;
- m_Target = Callback.GetPlayer();
-
- m_World->BroadcastEntityMetadata(*this);
+ if ((GetWorld()->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) - GetWorld()->GetSkyDarkness() < 15) && !Callback.GetPlayer()->IsGameModeCreative())
+ {
+ super::EventSeePlayer(Callback.GetPlayer());
+ m_EMState = CHASING;
+ m_bIsScreaming = true;
+ GetWorld()->BroadcastEntityMetadata(*this);
+ }
}
+void cEnderman::EventLosePlayer()
+{
+ super::EventLosePlayer();
+ m_bIsScreaming = false;
+ GetWorld()->BroadcastEntityMetadata(*this);
+}
\ No newline at end of file
diff --git a/src/Mobs/Enderman.h b/src/Mobs/Enderman.h
index be6e7bdf4..044b40511 100644
--- a/src/Mobs/Enderman.h
+++ b/src/Mobs/Enderman.h
@@ -18,7 +18,8 @@ public:
CLASS_PROTODEF(cEnderman);
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
- virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void CheckEventSeePlayer(void) override;
+ virtual void EventLosePlayer(void) override;
bool IsScreaming(void) const {return m_bIsScreaming; }
BLOCKTYPE GetCarriedBlock(void) const {return CarriedBlock; }
From 0690788cdfefbec3c74057e0b60d9f5aae935303 Mon Sep 17 00:00:00 2001
From: worktycho
Date: Wed, 4 Jun 2014 14:16:24 +0100
Subject: [PATCH 004/751] Replaced strange algebra with dot product.
10 degrees is a completely arbitary constant I pulled from nowhere. Feel free to adjust this value.
---
src/Mobs/Enderman.cpp | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 416b541ed..d26639a75 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -42,12 +42,14 @@ public:
return false;
}
- Direction.Normalize();
Vector3d LookVector = a_Player->GetLookVector();
- LookVector.Normalize();
+ double dot = Direction.Dot(LookVector);
- if ((Direction - LookVector).SqrLength() > 0.02)
+ // 0.09 rad ~ 5 degrees.
+ // If the players crosshars are 10 degrees from the line linking the endermen
+ // It counts as looking.
+ if (dot > cos(0.09))
{
return false;
}
@@ -140,4 +142,4 @@ void cEnderman::EventLosePlayer()
super::EventLosePlayer();
m_bIsScreaming = false;
GetWorld()->BroadcastEntityMetadata(*this);
-}
\ No newline at end of file
+}
From afda11a495de5b48ad17334da0e3f3b801d02f9b Mon Sep 17 00:00:00 2001
From: worktycho
Date: Mon, 30 Jun 2014 19:33:10 +0100
Subject: [PATCH 005/751] Changed comment
---
src/Mobs/Enderman.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index d26639a75..6b7a22757 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -47,7 +47,7 @@ public:
double dot = Direction.Dot(LookVector);
// 0.09 rad ~ 5 degrees.
- // If the players crosshars are 10 degrees from the line linking the endermen
+ // If the players crosshair is within 5 degrees of the endermen
// It counts as looking.
if (dot > cos(0.09))
{
From f79e68266426993af94f811afc8296e7b159462a Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 27 Jul 2014 00:03:00 +0200
Subject: [PATCH 006/751] Fixed plugin count and fixed plugin loading, when
settings.ini was regenerated.
---
src/Bindings/PluginManager.cpp | 46 ++++++++++++++++++++++------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 088b92a6d..1d97d1331 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -124,44 +124,58 @@ void cPluginManager::ReloadPluginsNow(cIniFile & a_SettingsIni)
// Check if the Plugins section exists.
int KeyNum = a_SettingsIni.FindKey("Plugins");
- // If it does, how many plugins are there?
- int NumPlugins = ((KeyNum != -1) ? (a_SettingsIni.GetNumValues(KeyNum)) : 0);
-
if (KeyNum == -1)
{
InsertDefaultPlugins(a_SettingsIni);
+ KeyNum = a_SettingsIni.FindKey("Plugins");
}
- else if (NumPlugins > 0)
+
+ // How many plugins are there?
+ int NumPlugins = a_SettingsIni.GetNumValues(KeyNum);
+
+ for (int i = 0; i < NumPlugins; i++)
{
- for (int i = 0; i < NumPlugins; i++)
+ AString ValueName = a_SettingsIni.GetValueName(KeyNum, i);
+ if (ValueName.compare("Plugin") == 0)
{
- AString ValueName = a_SettingsIni.GetValueName(KeyNum, i);
- if (ValueName.compare("Plugin") == 0)
+ AString PluginFile = a_SettingsIni.GetValue(KeyNum, i);
+ if (!PluginFile.empty())
{
- AString PluginFile = a_SettingsIni.GetValue(KeyNum, i);
- if (!PluginFile.empty())
+ if (m_Plugins.find(PluginFile) != m_Plugins.end())
{
- if (m_Plugins.find(PluginFile) != m_Plugins.end())
- {
- LoadPlugin(PluginFile);
- }
+ LoadPlugin(PluginFile);
}
}
}
}
+
+ // Remove invalid plugins from the PluginMap.
+ for (PluginMap::iterator itr = m_Plugins.begin(); itr != m_Plugins.end();)
+ {
+ if (itr->second == NULL)
+ {
+ PluginMap::iterator thiz = itr;
+ ++thiz;
+ m_Plugins.erase(itr);
+ itr = thiz;
+ continue;
+ }
+ ++itr;
+ }
+
size_t NumLoadedPlugins = GetNumPlugins();
if (NumLoadedPlugins == 0)
{
LOG("-- No Plugins Loaded --");
}
- else if (NumLoadedPlugins > 1)
+ else if (NumLoadedPlugins == 1)
{
- LOG("-- Loaded %i Plugins --", (int)NumLoadedPlugins);
+ LOG("-- Loaded 1 Plugin --");
}
else
{
- LOG("-- Loaded 1 Plugin --");
+ LOG("-- Loaded %i Plugins --", (int)NumLoadedPlugins);
}
CallHookPluginsLoaded();
}
From a5cca16abe524fdbd756908ac157a0c9881463f3 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 27 Jul 2014 00:39:39 +0200
Subject: [PATCH 007/751] Add "Broadcasting" settings to world.ini
---
src/Entities/Player.cpp | 14 ++++++++------
src/Root.cpp | 4 ++--
src/Server.h | 4 ++--
src/World.cpp | 3 +++
src/World.h | 8 +++++++-
5 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index fcc8eb9a0..393afc3b6 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -890,7 +890,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
SaveToDisk(); // Save it, yeah the world is a tough place !
- if (a_TDI.Attacker == NULL)
+ if ((a_TDI.Attacker == NULL) && m_World->ShouldBroadcastDeathMessages())
{
AString DamageText;
switch (a_TDI.DamageType)
@@ -1208,11 +1208,13 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
}
else
{
- // First time, announce it
- cCompositeChat Msg;
- Msg.SetMessageType(mtSuccess);
- Msg.AddShowAchievementPart(GetName(), cStatInfo::GetName(a_Ach));
- m_World->BroadcastChat(Msg);
+ if (m_World->ShouldBroadcastAchievementMessages())
+ {
+ cCompositeChat Msg;
+ Msg.SetMessageType(mtSuccess);
+ Msg.AddShowAchievementPart(GetName(), cStatInfo::GetName(a_Ach));
+ m_World->BroadcastChat(Msg);
+ }
// Increment the statistic
StatValue New = m_Stats.AddValue(a_Ach);
diff --git a/src/Root.cpp b/src/Root.cpp
index b03a13382..efa21b775 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -269,12 +269,12 @@ void cRoot::LoadWorlds(cIniFile & IniFile)
{
// First get the default world
AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world");
- m_pDefaultWorld = new cWorld( DefaultWorldName.c_str());
+ m_pDefaultWorld = new cWorld(DefaultWorldName.c_str());
m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld;
// Then load the other worlds
unsigned int KeyNum = IniFile.FindKey("Worlds");
- unsigned int NumWorlds = IniFile.GetNumValues( KeyNum);
+ unsigned int NumWorlds = IniFile.GetNumValues(KeyNum);
if (NumWorlds <= 0)
{
return;
diff --git a/src/Server.h b/src/Server.h
index b03359f03..c1640b388 100644
--- a/src/Server.h
+++ b/src/Server.h
@@ -63,12 +63,12 @@ public: // tolua_export
const AString & GetDescription(void) const {return m_Description; }
// Player counts:
- int GetMaxPlayers(void) const {return m_MaxPlayers; }
+ int GetMaxPlayers(void) const { return m_MaxPlayers; }
int GetNumPlayers(void) const;
void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; }
// Hardcore mode or not:
- bool IsHardcore(void) const {return m_bIsHardcore; }
+ bool IsHardcore(void) const { return m_bIsHardcore; }
// tolua_end
diff --git a/src/World.cpp b/src/World.cpp
index 7ad350e24..ff393bc2b 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -522,6 +522,9 @@ void cWorld::Start(void)
AString Dimension = IniFile.GetValueSet("General", "Dimension", "Overworld");
m_Dimension = StringToDimension(Dimension);
+ m_BroadcastDeathMessages = IniFile.GetValueSetB("Broadcasting", "BroadcastDeathMessages", true);
+ m_BroadcastAchievementMessages = IniFile.GetValueSetB("Broadcasting", "BroadcastAchievementMessages", true);
+
// Try to find the "SpawnPosition" key and coord values in the world configuration, set the flag if found
int KeyNum = IniFile.FindKey("SpawnPosition");
m_IsSpawnExplicitlySet =
diff --git a/src/World.h b/src/World.h
index 9658178ae..cb77361f6 100644
--- a/src/World.h
+++ b/src/World.h
@@ -622,7 +622,10 @@ public:
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
-
+
+ bool ShouldBroadcastDeathMessages(void) const { return m_BroadcastDeathMessages; }
+ bool ShouldBroadcastAchievementMessages(void) const { return m_BroadcastAchievementMessages; }
+
// tolua_end
/** Saves all chunks immediately. Dangerous interface, may deadlock, use QueueSaveAllChunks() instead */
@@ -842,6 +845,9 @@ private:
double m_SpawnY;
double m_SpawnZ;
+ bool m_BroadcastDeathMessages;
+ bool m_BroadcastAchievementMessages;
+
double m_WorldAgeSecs; // World age, in seconds. Is only incremented, cannot be set by plugins.
double m_TimeOfDaySecs; // Time of day in seconds. Can be adjusted. Is wrapped to zero each day.
Int64 m_WorldAge; // World age in ticks, calculated off of m_WorldAgeSecs
From 7f9f46c9114837a6edaae53385b7b7970b91abbd Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 27 Jul 2014 13:47:21 +0200
Subject: [PATCH 008/751] Fixed group color's.
---
src/ClientHandle.cpp | 19 ++++---------------
src/GroupManager.cpp | 2 +-
2 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index e4ad218a2..116ea459e 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1973,28 +1973,17 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock
void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData)
{
- bool ShouldAppendChatPrefixes = true;
-
- if (GetPlayer()->GetWorld() == NULL)
+ cWorld * World = GetPlayer()->GetWorld();
+ if (World == NULL)
{
- cWorld * World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName());
+ World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName());
if (World == NULL)
{
World = cRoot::Get()->GetDefaultWorld();
}
-
- if (!World->ShouldUseChatPrefixes())
- {
- ShouldAppendChatPrefixes = false;
- }
- }
- else if (!GetPlayer()->GetWorld()->ShouldUseChatPrefixes())
- {
- ShouldAppendChatPrefixes = false;
}
- AString Message = FormatMessageType(ShouldAppendChatPrefixes, a_ChatPrefix, a_AdditionalData);
-
+ AString Message = FormatMessageType(World->ShouldUseChatPrefixes(), a_ChatPrefix, a_AdditionalData);
m_Protocol->SendChat(Message.append(a_Message));
}
diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp
index 32c2f1c97..bc9bb67be 100644
--- a/src/GroupManager.cpp
+++ b/src/GroupManager.cpp
@@ -153,7 +153,7 @@ bool cGroupManager::LoadGroups()
AString Color = IniFile.GetValue(KeyName, "Color", "-");
if ((Color != "-") && (Color.length() >= 1))
{
- Group->SetColor(cChatColor::Delimiter + Color[0]);
+ Group->SetColor(cChatColor::Delimiter + Color);
}
else
{
From 9be92fa71df5620421c5f64cfa21cb6448a7686c Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 27 Jul 2014 20:44:00 +0200
Subject: [PATCH 009/751] Use Color[0].
---
src/GroupManager.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp
index bc9bb67be..e03f8bca3 100644
--- a/src/GroupManager.cpp
+++ b/src/GroupManager.cpp
@@ -153,7 +153,7 @@ bool cGroupManager::LoadGroups()
AString Color = IniFile.GetValue(KeyName, "Color", "-");
if ((Color != "-") && (Color.length() >= 1))
{
- Group->SetColor(cChatColor::Delimiter + Color);
+ Group->SetColor(cChatColor::Delimiter + AString(&Color[0]));
}
else
{
From 3d730403278bca630856ce7d275aed920aa20235 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 27 Jul 2014 21:14:45 +0200
Subject: [PATCH 010/751] Use AString(1, Color[0])
---
src/GroupManager.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp
index e03f8bca3..f1f86dc0f 100644
--- a/src/GroupManager.cpp
+++ b/src/GroupManager.cpp
@@ -153,7 +153,7 @@ bool cGroupManager::LoadGroups()
AString Color = IniFile.GetValue(KeyName, "Color", "-");
if ((Color != "-") && (Color.length() >= 1))
{
- Group->SetColor(cChatColor::Delimiter + AString(&Color[0]));
+ Group->SetColor(cChatColor::Delimiter + AString(1, Color[0]));
}
else
{
From 2bdc2701f4208f5a705fafceec3685a9834714a1 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 27 Jul 2014 21:58:00 +0200
Subject: [PATCH 011/751] Change Group->SetColor() again.
---
src/GroupManager.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp
index f1f86dc0f..4c3dfc6f0 100644
--- a/src/GroupManager.cpp
+++ b/src/GroupManager.cpp
@@ -153,7 +153,7 @@ bool cGroupManager::LoadGroups()
AString Color = IniFile.GetValue(KeyName, "Color", "-");
if ((Color != "-") && (Color.length() >= 1))
{
- Group->SetColor(cChatColor::Delimiter + AString(1, Color[0]));
+ Group->SetColor(AString(cChatColor::Delimiter) + Color[0]);
}
else
{
From f5f9656917c0cb0cc68aee50178aafd3f24c417f Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 28 Jul 2014 12:37:48 +0200
Subject: [PATCH 012/751] cAuthenticator: Added GetUUIDsFromPlayerNames().
---
src/Protocol/Authenticator.cpp | 99 ++++++++++++++++++++++++++++++++--
src/Protocol/Authenticator.h | 20 +++++++
2 files changed, 116 insertions(+), 3 deletions(-)
diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp
index 2a7cbc7bc..75721589f 100644
--- a/src/Protocol/Authenticator.cpp
+++ b/src/Protocol/Authenticator.cpp
@@ -17,6 +17,8 @@
#define DEFAULT_AUTH_SERVER "sessionserver.mojang.com"
#define DEFAULT_AUTH_ADDRESS "/session/minecraft/hasJoined?username=%USERNAME%&serverId=%SERVERID%"
+#define DEFAULT_NAME_TO_UUID_SERVER "api.mojang.com"
+#define DEFAULT_NAME_TO_UUID_ADDRESS "/profiles/minecraft"
/** This is the data of the root certs for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert:
Downloaded from http://certs.starfieldtech.com/repository/ */
@@ -83,6 +85,8 @@ cAuthenticator::cAuthenticator(void) :
super("cAuthenticator"),
m_Server(DEFAULT_AUTH_SERVER),
m_Address(DEFAULT_AUTH_ADDRESS),
+ m_NameToUUIDServer(DEFAULT_NAME_TO_UUID_SERVER),
+ m_NameToUUIDAddress(DEFAULT_NAME_TO_UUID_ADDRESS),
m_ShouldAuthenticate(true)
{
}
@@ -102,9 +106,11 @@ cAuthenticator::~cAuthenticator()
void cAuthenticator::ReadINI(cIniFile & IniFile)
{
- m_Server = IniFile.GetValueSet("Authentication", "Server", DEFAULT_AUTH_SERVER);
- m_Address = IniFile.GetValueSet("Authentication", "Address", DEFAULT_AUTH_ADDRESS);
+ m_Server = IniFile.GetValueSet ("Authentication", "Server", DEFAULT_AUTH_SERVER);
+ m_Address = IniFile.GetValueSet ("Authentication", "Address", DEFAULT_AUTH_ADDRESS);
m_ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true);
+ m_NameToUUIDServer = IniFile.GetValueSet ("Authentication", "NameToUUIDServer", DEFAULT_NAME_TO_UUID_SERVER);
+ m_NameToUUIDAddress = IniFile.GetValueSet ("Authentication", "NameToUUIDAddress", DEFAULT_NAME_TO_UUID_ADDRESS);
}
@@ -151,6 +157,93 @@ void cAuthenticator::Stop(void)
+AStringVector cAuthenticator::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames)
+{
+ AStringVector res;
+
+ // Create the request body - a JSON containing all the playernames:
+ Json::Value root;
+ for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr)
+ {
+ Json::Value req(*itr);
+ root.append(req);
+ } // for itr - a_PlayerNames[]
+ Json::FastWriter Writer;
+ AString RequestBody = Writer.write(root);
+
+ // Create the HTTP request:
+ AString Request;
+ Request += "POST " + m_NameToUUIDAddress + " HTTP/1.1\r\n";
+ Request += "Host: " + m_NameToUUIDServer + "\r\n";
+ Request += "User-Agent: MCServer\r\n";
+ Request += "Connection: close\r\n";
+ Request += "Content-Type: application/json\r\n";
+ Request += Printf("Content-Length: %u\r\n", (unsigned)RequestBody.length());
+ Request += "\r\n";
+ Request += RequestBody;
+
+ // Get the response from the server:
+ AString Response;
+ if (!SecureGetFromAddress(StarfieldCACert(), m_NameToUUIDServer, Request, Response))
+ {
+ return res;
+ }
+
+ // Check the HTTP status line:
+ const AString Prefix("HTTP/1.1 200 OK");
+ AString HexDump;
+ if (Response.compare(0, Prefix.size(), Prefix))
+ {
+ LOGINFO("%s failed: bad HTTP status line received", __FUNCTION__);
+ LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ return res;
+ }
+
+ // Erase the HTTP headers from the response:
+ size_t idxHeadersEnd = Response.find("\r\n\r\n");
+ if (idxHeadersEnd == AString::npos)
+ {
+ LOGINFO("%s failed: bad HTTP response header received", __FUNCTION__);
+ LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ return res;
+ }
+ Response.erase(0, idxHeadersEnd + 4);
+
+ // Parse the returned string into Json:
+ Json::Reader reader;
+ if (!reader.parse(Response, root, false) || !root.isArray())
+ {
+ LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON!", __FUNCTION__);
+ LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ return res;
+ }
+
+ // Fill in the resulting array; do not expect to get the UUIDs in the same order as the inputs:
+ size_t len = a_PlayerNames.size();
+ size_t JsonCount = root.size();
+ res.resize(len);
+ for (size_t idx = 0; idx < len; idx++) // For each input username...
+ {
+ const AString & InputName = a_PlayerNames[idx];
+ for (size_t IdxJson = 0; IdxJson < JsonCount; ++IdxJson)
+ {
+ Json::Value & Val = root[IdxJson];
+ AString JsonName = Val.get("name", "").asString();
+ if (NoCaseCompare(JsonName, InputName) == 0)
+ {
+ res[idx] = Val.get("id", "").asString();
+ break;
+ }
+ } // for IdxJson - root[]
+ } // for idx - a_PlayerNames[] / res[]
+
+ return res;
+}
+
+
+
+
+
void cAuthenticator::Execute(void)
{
for (;;)
@@ -307,7 +400,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
a_UUID = root.get("id", "").asString();
a_Properties = root["properties"];
- // If the UUID doesn't contain the hashes, insert them at the proper places:
+ // If the UUID doesn't contain the dashes, insert them at the proper places:
if (a_UUID.size() == 32)
{
a_UUID.insert(8, "-");
diff --git a/src/Protocol/Authenticator.h b/src/Protocol/Authenticator.h
index 244d94c0b..82ecb1f7a 100644
--- a/src/Protocol/Authenticator.h
+++ b/src/Protocol/Authenticator.h
@@ -52,6 +52,12 @@ public:
/** Stops the authenticator thread. The thread may be started and stopped repeatedly */
void Stop(void);
+
+ /** Converts the player names into UUIDs.
+ a_PlayerName[idx] will be converted to UUID and returned as idx-th value
+ The UUID will be empty on error.
+ Blocking operation, do not use in world-tick thread! */
+ AStringVector GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName);
private:
@@ -76,8 +82,22 @@ private:
cUserList m_Queue;
cEvent m_QueueNonempty;
+ /** The server that is to be contacted for auth / UUID conversions */
AString m_Server;
+
+ /** The URL to use for auth, without server part.
+ %USERNAME% will be replaced with actual user name.
+ %SERVERID% will be replaced with server's ID.
+ For example "/session/minecraft/hasJoined?username=%USERNAME%&serverId=%SERVERID%". */
AString m_Address;
+
+ /** The server to connect to when converting player names to UUIDs. For example "api.mojang.com". */
+ AString m_NameToUUIDServer;
+
+ /** The URL to use for converting player names to UUIDs, without server part.
+ For example "/profiles/page/1". */
+ AString m_NameToUUIDAddress;
+
AString m_PropertiesAddress;
bool m_ShouldAuthenticate;
From 1acd03f96f9b1133e1f76d76004f5fcddd0c4788 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 28 Jul 2014 17:09:39 +0200
Subject: [PATCH 013/751] Added cClientHandle:GetUUIDsFromPlayerNames() to Lua
API.
---
MCServer/Plugins/APIDump/APIDesc.lua | 1 +
src/Bindings/ManualBindings.cpp | 65 ++++++++++++++++++++++++++--
2 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index e65da1d16..f29c47338 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -529,6 +529,7 @@ end
GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client. Note that this may be nil, for example if the player object is not yet spawned." },
GetUniqueID = { Params = "", Return = "number", Notes = "Returns the UniqueID of the client used to identify the client in the server" },
GetUUID = { Params = "", Return = "string", Notes = "Returns the authentication-based UUID of the client. This UUID should be used to identify the player when persisting any player-related data." },
+ GetUUIDsFromPlayerNames = { Params = "PlayerNames", Return = "table", Notes = "(STATIC) Returns a table that contains the map, 'PlayerName' -> 'UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. Queries the Mojang servers for the results. WARNING: Do NOT use this function while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely. NOTE: Mojang API has a limit of 100 names per query and 600 queries per 10 minutes (may change)" },
GetUsername = { Params = "", Return = "string", Notes = "Returns the username that the client has provided" },
GetViewDistance = { Params = "", Return = "number", Notes = "Returns the viewdistance (number of chunks loaded for the player in each direction)" },
HasPluginChannel = { Params = "ChannelName", Return = "bool", Notes = "Returns true if the client has registered to receive messages on the specified plugin channel." },
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index df9687fc0..28ee00b36 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -26,6 +26,7 @@
#include "../BlockEntities/MobHeadEntity.h"
#include "../BlockEntities/FlowerPotEntity.h"
#include "../LineBlockTracer.h"
+#include "../Protocol/Authenticator.h"
#include "../WorldStorage/SchematicFileSerializer.h"
#include "../CompositeChat.h"
@@ -2156,6 +2157,63 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L)
+static int tolua_cClientHandle_GetUUIDsFromPlayerNames(lua_State * L)
+{
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cClientHandle") ||
+ !S.CheckParamTable(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Convert the input table into AStringVector:
+ AStringVector PlayerNames;
+ int NumNames = luaL_getn(L, 2);
+ PlayerNames.reserve(NumNames);
+ for (int i = 1; i <= NumNames; i++)
+ {
+ lua_rawgeti(L, 2, i);
+ AString Name;
+ S.GetStackValue(3, Name);
+ if (!Name.empty())
+ {
+ PlayerNames.push_back(Name);
+ }
+ lua_pop(L, 1);
+ }
+
+ // Push the output table onto the stack:
+ lua_newtable(L); // stack index 3
+
+ // Get the UUIDs:
+ AStringVector UUIDs = cRoot::Get()->GetAuthenticator().GetUUIDsFromPlayerNames(PlayerNames);
+ if (UUIDs.size() != PlayerNames.size())
+ {
+ // A hard error has occured while processing the request, no UUIDs were returned. Return an empty table:
+ return 1;
+ }
+
+ // Convert to output table, PlayerName -> UUID:
+ for (int i = 0; i < NumNames; i++)
+ {
+ if (UUIDs[i].empty())
+ {
+ // No UUID was provided for PlayerName[i], skip it in the resulting table
+ continue;
+ }
+ lua_pushlstring(L, UUIDs[i].c_str(), UUIDs[i].length());
+ lua_setfield(L, 3, PlayerNames[i].c_str());
+ }
+ return 1;
+}
+
+
+
+
+
static int Lua_ItemGrid_GetSlotCoords(lua_State * L)
{
tolua_Error tolua_err;
@@ -3083,9 +3141,10 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cClientHandle");
- tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE);
- tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE);
- tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage);
+ tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE);
+ tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE);
+ tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage);
+ tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cClientHandle_GetUUIDsFromPlayerNames);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cItemGrid");
From b6677efecdd026a7eb8d652a067e4770182cd7c1 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 28 Jul 2014 17:14:23 +0200
Subject: [PATCH 014/751] Debuggers: Added an example for
cClientHandle:GetUUIDsFromPlayerNames().
---
MCServer/Plugins/Debuggers/Debuggers.lua | 31 ++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index b402c1867..80416acc7 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -80,6 +80,7 @@ function Initialize(Plugin)
TestBlockAreasString()
TestStringBase64()
+ TestUUIDFromName()
--[[
-- Test cCompositeChat usage in console-logging:
@@ -275,6 +276,36 @@ end
+function TestUUIDFromName()
+ LOG("Testing UUID-from-Name resolution...")
+
+ -- Test by querying a few existing names, along with a non-existent one:
+ local PlayerNames =
+ {
+ "xoft",
+ "aloe_vera",
+ "nonexistent_player",
+ }
+ -- WARNING: Blocking operation! DO NOT USE IN TICK THREAD!
+ local UUIDs = cClientHandle:GetUUIDsFromPlayerNames(PlayerNames)
+
+ -- Log the results:
+ for _, name in ipairs(PlayerNames) do
+ local UUID = UUIDs[name]
+ if (UUID == nil) then
+ LOG(" UUID(" .. name .. ") not found.")
+ else
+ LOG(" UUID(" .. name .. ") = \"" .. UUID .. "\"")
+ end
+ end
+
+ LOG("UUID-from-Name resolution test finished.")
+end
+
+
+
+
+
function TestSQLiteBindings()
LOG("Testing SQLite bindings...");
From 036a8ff98e890071089e9938cb87c5c4323152f0 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 28 Jul 2014 19:59:53 +0200
Subject: [PATCH 015/751] Added SQLiteCpp library.
This provides C++ wrappers for SQLite, making it safer to use in the C++ environment.
---
.gitmodules | 3 +++
CMakeLists.txt | 9 +++++++++
Install/SQLiteCpp-LICENSE.txt | 20 ++++++++++++++++++++
Install/Zip2008.list | 1 +
lib/SQLiteCpp | 1 +
5 files changed, 34 insertions(+)
create mode 100644 Install/SQLiteCpp-LICENSE.txt
create mode 160000 lib/SQLiteCpp
diff --git a/.gitmodules b/.gitmodules
index 2aaee3624..8e63ee0a9 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -10,3 +10,6 @@
[submodule "lib/polarssl"]
path = lib/polarssl
url = https://github.com/mc-server/polarssl
+[submodule "lib/SQLiteCpp"]
+ path = lib/SQLiteCpp
+ url = https://github.com/mc-server/SQLiteCpp.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a6400c1b4..478b79047 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,6 +53,14 @@ endif()
project (MCServer)
+# Set options for SQLiteCpp, disable all their tests and lints:
+set(SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "Run cpplint.py tool for Google C++ StyleGuide." FORCE)
+set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "Run cppcheck C++ static analysis tool." FORCE)
+set(SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "Run Doxygen C++ documentation tool." FORCE)
+set(SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "Build examples." FORCE)
+set(SQLITECPP_BUILD_TESTS OFF CACHE BOOL "Build and run tests." FORCE)
+set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "Add the internal SQLite3 source to the project." FORCE)
+
# Include all the libraries:
add_subdirectory(lib/inifile/)
add_subdirectory(lib/jsoncpp/)
@@ -60,6 +68,7 @@ add_subdirectory(lib/zlib/)
add_subdirectory(lib/lua/)
add_subdirectory(lib/tolua++/)
add_subdirectory(lib/sqlite/)
+add_subdirectory(lib/SQLiteCpp/)
add_subdirectory(lib/expat/)
add_subdirectory(lib/luaexpat/)
diff --git a/Install/SQLiteCpp-LICENSE.txt b/Install/SQLiteCpp-LICENSE.txt
new file mode 100644
index 000000000..ec952abba
--- /dev/null
+++ b/Install/SQLiteCpp-LICENSE.txt
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2012-2014 Sebastien Rombauts (sebastien.rombauts@gmail.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/Install/Zip2008.list b/Install/Zip2008.list
index b118ccbf9..5736867d8 100644
--- a/Install/Zip2008.list
+++ b/Install/Zip2008.list
@@ -11,4 +11,5 @@ MCServer*debug.cmd
Lua-LICENSE.txt
LuaExpat-license.html
LuaSQLite3-LICENSE.txt
+SQLiteCpp-LICENSE.txt
MersenneTwister-LICENSE.txt
diff --git a/lib/SQLiteCpp b/lib/SQLiteCpp
new file mode 160000
index 000000000..27b9d1118
--- /dev/null
+++ b/lib/SQLiteCpp
@@ -0,0 +1 @@
+Subproject commit 27b9d111818af3b05bcf4153bb6e380fe1dd6816
From 5fb5f6671f2b138dc56187183f0650b70a4d2eb4 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 28 Jul 2014 20:16:24 +0200
Subject: [PATCH 016/751] Fixed include directories for SQLiteCpp.
---
CMakeLists.txt | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 478b79047..2b30e1e0b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -72,6 +72,12 @@ add_subdirectory(lib/SQLiteCpp/)
add_subdirectory(lib/expat/)
add_subdirectory(lib/luaexpat/)
+# Add proper include directories so that SQLiteCpp can find SQLite3:
+get_property(SQLITECPP_INCLUDES DIRECTORY "lib/SQLiteCpp/" PROPERTY INCLUDE_DIRECTORIES)
+set(SQLITECPP_INCLUDES "${SQLITECPP_INCLUDES}" "${CMAKE_CURRENT_SOURCE_DIR}/lib/sqlite/")
+message("SQLiteCpp includes: " "${SQLITECPP_INCLUDES}")
+set_property(DIRECTORY lib/SQLiteCpp/ PROPERTY INCLUDE_DIRECTORIES "${SQLITECPP_INCLUDES}")
+
if (WIN32)
add_subdirectory(lib/luaproxy/)
endif()
From 7f7604a186885107d0bd9625d969aef45a60dcce Mon Sep 17 00:00:00 2001
From: Mattes D
Date: Mon, 28 Jul 2014 22:06:47 +0200
Subject: [PATCH 017/751] Fixed SQLiteCpp include paths for MSVC2010+.
---
CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b30e1e0b..dd9b1e67c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -75,8 +75,8 @@ add_subdirectory(lib/luaexpat/)
# Add proper include directories so that SQLiteCpp can find SQLite3:
get_property(SQLITECPP_INCLUDES DIRECTORY "lib/SQLiteCpp/" PROPERTY INCLUDE_DIRECTORIES)
set(SQLITECPP_INCLUDES "${SQLITECPP_INCLUDES}" "${CMAKE_CURRENT_SOURCE_DIR}/lib/sqlite/")
-message("SQLiteCpp includes: " "${SQLITECPP_INCLUDES}")
set_property(DIRECTORY lib/SQLiteCpp/ PROPERTY INCLUDE_DIRECTORIES "${SQLITECPP_INCLUDES}")
+set_property(TARGET SQLiteCpp PROPERTY INCLUDE_DIRECTORIES "${SQLITECPP_INCLUDES}")
if (WIN32)
add_subdirectory(lib/luaproxy/)
From adae2b70b1733a280fe342ca6d0dca7e37301f4f Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Tue, 29 Jul 2014 22:31:31 +0200
Subject: [PATCH 018/751] Added cBlockInfo::CanBeTerraformed and made finishers
use it I might have forgotten some of them though
---
src/BlockInfo.cpp | 21 +++++++++++++++++++++
src/BlockInfo.h | 4 ++++
src/Generating/Caves.cpp | 24 ++----------------------
src/Generating/RoughRavines.cpp | 26 ++++----------------------
4 files changed, 31 insertions(+), 44 deletions(-)
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 602deb26d..311a53c42 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -17,6 +17,7 @@ cBlockInfo::cBlockInfo()
, m_IsSnowable(false)
, m_IsSolid(true)
, m_FullyOccupiesVoxel(false)
+ , m_CanBeTerraformed(false)
, m_Handler(NULL)
{}
@@ -548,6 +549,26 @@ void cBlockInfo::Initialize(cBlockInfoArray & a_Info)
a_Info[E_BLOCK_STONE ].m_FullyOccupiesVoxel = true;
a_Info[E_BLOCK_STONE_BRICKS ].m_FullyOccupiesVoxel = true;
a_Info[E_BLOCK_WOOL ].m_FullyOccupiesVoxel = true;
+
+
+ // Blocks that can be terraformed
+ a_Info[E_BLOCK_COAL_ORE ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_COBBLESTONE ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_DIAMOND_ORE ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_DIRT ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_GOLD_ORE ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_GRASS ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_GRAVEL ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_HARDENED_CLAY ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_IRON_ORE ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_MYCELIUM ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_NETHERRACK ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_REDSTONE_ORE ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_SAND ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_SANDSTONE ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_STAINED_CLAY ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_STONE ].m_CanBeTerraformed = true;
}
diff --git a/src/BlockInfo.h b/src/BlockInfo.h
index e6ce566c5..4c66c095a 100644
--- a/src/BlockInfo.h
+++ b/src/BlockInfo.h
@@ -45,6 +45,9 @@ public:
/** Does this block fully occupy its voxel - is it a 'full' block? */
bool m_FullyOccupiesVoxel;
+ /** Can a finisher change it? */
+ bool m_CanBeTerraformed;
+
// tolua_end
/** Associated block handler. */
@@ -60,6 +63,7 @@ public:
inline static bool IsSnowable (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSnowable; }
inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; }
inline static bool FullyOccupiesVoxel (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel; }
+ inline static bool CanBeTerraformed (BLOCKTYPE a_Type) { return Get(a_Type).m_CanBeTerraformed; }
// tolua_end
diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp
index 3b71efb57..6fc371958 100644
--- a/src/Generating/Caves.cpp
+++ b/src/Generating/Caves.cpp
@@ -497,29 +497,9 @@ void cCaveTunnel::ProcessChunk(
int SqDist = (DifX - x) * (DifX - x) + (DifY - y) * (DifY - y) + (DifZ - z) * (DifZ - z);
if (4 * SqDist <= SqRad)
{
- switch (cChunkDef::GetBlock(a_BlockTypes, x, y, z))
+ if (cBlockInfo::CanBeTerraformed(cChunkDef::GetBlock(a_BlockTypes, x, y, z)))
{
- // Only carve out these specific block types
- case E_BLOCK_DIRT:
- case E_BLOCK_GRASS:
- case E_BLOCK_STONE:
- case E_BLOCK_COBBLESTONE:
- case E_BLOCK_GRAVEL:
- case E_BLOCK_SAND:
- case E_BLOCK_SANDSTONE:
- case E_BLOCK_SOULSAND:
- case E_BLOCK_NETHERRACK:
- case E_BLOCK_COAL_ORE:
- case E_BLOCK_IRON_ORE:
- case E_BLOCK_GOLD_ORE:
- case E_BLOCK_DIAMOND_ORE:
- case E_BLOCK_REDSTONE_ORE:
- case E_BLOCK_REDSTONE_ORE_GLOWING:
- {
- cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_AIR);
- break;
- }
- default: break;
+ cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_AIR);
}
}
} // for y
diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp
index badc7768e..2ee3704b3 100644
--- a/src/Generating/RoughRavines.cpp
+++ b/src/Generating/RoughRavines.cpp
@@ -201,29 +201,11 @@ protected:
{
continue;
}
- switch (a_ChunkDesc.GetBlockType(x, y, z))
+
+ if (cBlockInfo::CanBeTerraformed(a_ChunkDesc.GetBlockType(x, y, z)))
{
- // Only carve out these specific block types
- case E_BLOCK_DIRT:
- case E_BLOCK_GRASS:
- case E_BLOCK_STONE:
- case E_BLOCK_COBBLESTONE:
- case E_BLOCK_GRAVEL:
- case E_BLOCK_SAND:
- case E_BLOCK_SANDSTONE:
- case E_BLOCK_NETHERRACK:
- case E_BLOCK_COAL_ORE:
- case E_BLOCK_IRON_ORE:
- case E_BLOCK_GOLD_ORE:
- case E_BLOCK_DIAMOND_ORE:
- case E_BLOCK_REDSTONE_ORE:
- case E_BLOCK_REDSTONE_ORE_GLOWING:
- {
- a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR);
- break;
- }
- default: break;
- } // switch (BlockType)
+ a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR);
+ }
} // for y
} // for x, z - a_BlockTypes
} // for itr - m_Points[]
From 931443ac67cefade2ebd0d29fd65a49d22293ea2 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Tue, 29 Jul 2014 22:40:40 +0200
Subject: [PATCH 019/751] Added soulsand to the terraformed list.
---
src/BlockInfo.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 311a53c42..4bc3fbbdc 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -567,6 +567,7 @@ void cBlockInfo::Initialize(cBlockInfoArray & a_Info)
a_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_CanBeTerraformed = true;
a_Info[E_BLOCK_SAND ].m_CanBeTerraformed = true;
a_Info[E_BLOCK_SANDSTONE ].m_CanBeTerraformed = true;
+ a_Info[E_BLOCK_SOULSAND ].m_CanBeTerraformed = true;
a_Info[E_BLOCK_STAINED_CLAY ].m_CanBeTerraformed = true;
a_Info[E_BLOCK_STONE ].m_CanBeTerraformed = true;
}
From 9a4d80fc3b9dbaa09c8e6d9e8021762a486f280f Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 30 Jul 2014 00:45:03 +0200
Subject: [PATCH 020/751] Fixed compile error with clang.
---
src/Generating/FinishGen.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h
index ed32768b3..cf84a0336 100644
--- a/src/Generating/FinishGen.h
+++ b/src/Generating/FinishGen.h
@@ -163,7 +163,7 @@ public:
m_Amount(a_Amount)
{
// Initialize all the block types.
- for (int idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx)
+ for (size_t idx = 0; idx < (size_t)ARRAYCOUNT(m_IsAllowedBelow); ++idx)
{
m_IsAllowedBelow[idx] = false;
}
@@ -175,7 +175,7 @@ public:
}
// Initialize all the biome types.
- for (int idx = 0; idx < ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
+ for (size_t idx = 0; idx < (size_t)ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
{
m_IsBiomeAllowed[idx] = false;
}
From 438e4088d6a38f9904a36f2e1a358965d9fb4a26 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 30 Jul 2014 01:22:51 +0200
Subject: [PATCH 021/751] Changed size_t to 'unsigned long'
---
src/Generating/FinishGen.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h
index cf84a0336..7171036e2 100644
--- a/src/Generating/FinishGen.h
+++ b/src/Generating/FinishGen.h
@@ -163,7 +163,7 @@ public:
m_Amount(a_Amount)
{
// Initialize all the block types.
- for (size_t idx = 0; idx < (size_t)ARRAYCOUNT(m_IsAllowedBelow); ++idx)
+ for (unsigned long idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx)
{
m_IsAllowedBelow[idx] = false;
}
@@ -175,7 +175,7 @@ public:
}
// Initialize all the biome types.
- for (size_t idx = 0; idx < (size_t)ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
+ for (unsigned long idx = 0; idx < ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
{
m_IsBiomeAllowed[idx] = false;
}
From 487c57242964ef4a86fc4f41c1c538d9df9ec892 Mon Sep 17 00:00:00 2001
From: archshift
Date: Tue, 29 Jul 2014 19:14:56 -0700
Subject: [PATCH 022/751] Entity.h: Moved constants out of some unnamed enum
---
src/Entities/Entity.h | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index e66194ca2..b9c280b6b 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -128,20 +128,20 @@ public:
esFireworkExploding = 17,
} ;
- enum
- {
- FIRE_TICKS_PER_DAMAGE = 10, ///< How many ticks to wait between damaging an entity when it stands in fire
- FIRE_DAMAGE = 1, ///< How much damage to deal when standing in fire
- LAVA_TICKS_PER_DAMAGE = 10, ///< How many ticks to wait between damaging an entity when it stands in lava
- LAVA_DAMAGE = 5, ///< How much damage to deal when standing in lava
- BURN_TICKS_PER_DAMAGE = 20, ///< How many ticks to wait between damaging an entity when it is burning
- BURN_DAMAGE = 1, ///< How much damage to deal when the entity is burning
- BURN_TICKS = 200, ///< How long to keep an entity burning after it has stood in lava / fire
- MAX_AIR_LEVEL = 300, ///< Maximum air an entity can have
- DROWNING_TICKS = 20, ///< Number of ticks per heart of damage
- VOID_BOUNDARY = -46, ///< At what position Y to begin applying void damage
- FALL_DAMAGE_HEIGHT = 4 ///< At what position Y fall damage is applied
- } ;
+ static const int FIRE_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in fire
+ static const int FIRE_DAMAGE = 1; ///< Damage to deal when standing in fire
+ static const int LAVA_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in lava
+ static const int LAVA_DAMAGE = 5; ///< Damage to deal when standing in lava
+ static const int BURN_TICKS_PER_DAMAGE = 20; ///< Ticks to wait between damaging an entity when it is burning
+ static const int BURN_DAMAGE = 1; ///< Damage to deal when the entity is burning
+
+ static const int BURN_TICKS = 200; ///< Ticks to keep an entity burning after it has stood in lava / fire
+
+ static const int MAX_AIR_LEVEL = 300; ///< Maximum air an entity can have
+ static const int DROWNING_TICKS = 20; ///< Number of ticks per heart of damage
+
+ static const int VOID_BOUNDARY = -46; ///< Y position to begin applying void damage
+ static const int FALL_DAMAGE_HEIGHT = 4; ///< Y difference after which fall damage is applied
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
virtual ~cEntity();
From 7022ae79886a9f90f30ff54387702d406b723837 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 07:08:29 +0200
Subject: [PATCH 023/751] Fixed FinishGen.h types.
---
src/Generating/FinishGen.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h
index 7171036e2..50a0fd2e7 100644
--- a/src/Generating/FinishGen.h
+++ b/src/Generating/FinishGen.h
@@ -163,7 +163,7 @@ public:
m_Amount(a_Amount)
{
// Initialize all the block types.
- for (unsigned long idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx)
+ for (size_t idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx)
{
m_IsAllowedBelow[idx] = false;
}
@@ -175,7 +175,7 @@ public:
}
// Initialize all the biome types.
- for (unsigned long idx = 0; idx < ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
+ for (size_t idx = 0; idx < ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
{
m_IsBiomeAllowed[idx] = false;
}
From 1d684697186de4340c6a1cc5aea6a14ffd19c002 Mon Sep 17 00:00:00 2001
From: archshift
Date: Tue, 29 Jul 2014 22:43:25 -0700
Subject: [PATCH 024/751] Fixed "Dependency" typos
---
.gitignore | 2 +-
src/Bindings/CMakeLists.txt | 4 ++--
src/CMakeLists.txt | 8 ++++----
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
index 51987336c..a4cbef72f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -64,7 +64,7 @@ install_mainfest.txt
src/MCServer
lib/tolua++/tolua
src/Bindings/Bindings.*
-src/Bindings/BindingDependecies.txt
+src/Bindings/BindingDependencies.txt
MCServer.dir/
src/AllFiles.lst
diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt
index 2ea2fa8c0..48e7ce79c 100644
--- a/src/Bindings/CMakeLists.txt
+++ b/src/Bindings/CMakeLists.txt
@@ -125,8 +125,8 @@ if (NOT MSVC)
DEPENDS ${BINDING_DEPENDENCIES}
)
endif ()
-set_source_files_properties(Bindings/Bindings.cpp PROPERTIES GENERATED TRUE)
-set_source_files_properties(Bindings/Bindings.h PROPERTIES GENERATED TRUE)
+set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES GENERATED TRUE)
+set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.h PROPERTIES GENERATED TRUE)
if(NOT MSVC)
add_library(Bindings ${SRCS} ${HDRS})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 29337cb2e..87599c60d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -151,10 +151,10 @@ if (NOT MSVC)
get_directory_property(BINDING_DEPENDENCIES DIRECTORY "Bindings" DEFINITION BINDING_DEPENDENCIES)
#clear file
- file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependecies.txt)
- foreach(dependecy ${BINDING_DEPENDECIES})
- #write each dependecy on a seperate line
- file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependecies.txt "${dependecy}\n")
+ file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependencies.txt)
+ foreach(dependency ${BINDING_DEPENDENCIES})
+ #write each dependency on a seperate line
+ file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependencies.txt "${dependency}\n")
endforeach()
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "Bindings.cpp Bindings.h")
From 75b7c3775528ced647eb5d7db3437d2856e01e7e Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 13:06:48 +0200
Subject: [PATCH 025/751] PreSimulator: Added configurations. You can now
choose if it should pregenerate something or not
---
src/Generating/ComposableGenerator.cpp | 7 ++++++-
src/Generating/FinishGen.cpp | 22 ++++++++++++++++++----
src/Generating/FinishGen.h | 7 ++++++-
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index a7659149a..cedb9aeb7 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -408,7 +408,12 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
}
else if (NoCaseCompare(*itr, "PreSimulator") == 0)
{
- m_FinishGens.push_back(new cFinishGenPreSimulator);
+ // Load the settings
+ bool PreSimulateFallingBlocks = a_IniFile.GetValueSetB("Generator", "PreSimulatorFallingBlocks", true);
+ bool PreSimulateWater = a_IniFile.GetValueSetB("Generator", "PreSimulatorWater", true);
+ bool PreSimulateLava = a_IniFile.GetValueSetB("Generator", "PreSimulatorLava", true);
+
+ m_FinishGens.push_back(new cFinishGenPreSimulator(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava));
}
else if (NoCaseCompare(*itr, "RainbowRoads") == 0)
{
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
index f53addb68..e8324095e 100644
--- a/src/Generating/FinishGen.cpp
+++ b/src/Generating/FinishGen.cpp
@@ -555,7 +555,10 @@ void cFinishGenBottomLava::GenFinish(cChunkDesc & a_ChunkDesc)
////////////////////////////////////////////////////////////////////////////////
// cFinishGenPreSimulator:
-cFinishGenPreSimulator::cFinishGenPreSimulator(void)
+cFinishGenPreSimulator::cFinishGenPreSimulator(bool a_PreSimulateFallingBlocks, bool a_PreSimulateWater, bool a_PreSimulateLava) :
+ m_PreSimulateFallingBlocks(a_PreSimulateFallingBlocks),
+ m_PreSimulateWater(a_PreSimulateWater),
+ m_PreSimulateLava(a_PreSimulateLava)
{
// Nothing needed yet
}
@@ -566,9 +569,20 @@ cFinishGenPreSimulator::cFinishGenPreSimulator(void)
void cFinishGenPreSimulator::GenFinish(cChunkDesc & a_ChunkDesc)
{
- CollapseSandGravel(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap());
- StationarizeFluid(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap(), E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER);
- StationarizeFluid(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap(), E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA);
+ if (m_PreSimulateFallingBlocks)
+ {
+ CollapseSandGravel(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap());
+ }
+
+ if (m_PreSimulateWater)
+ {
+ StationarizeFluid(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap(), E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER);
+ }
+
+ if (m_PreSimulateLava)
+ {
+ StationarizeFluid(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap(), E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA);
+ }
// TODO: other operations
}
diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h
index 50a0fd2e7..4a08d70c8 100644
--- a/src/Generating/FinishGen.h
+++ b/src/Generating/FinishGen.h
@@ -240,9 +240,14 @@ class cFinishGenPreSimulator :
public cFinishGen
{
public:
- cFinishGenPreSimulator(void);
+ cFinishGenPreSimulator(bool a_PreSimulateFallingBlocks, bool a_PreSimulateWater, bool a_PreSimulateLava);
protected:
+
+ bool m_PreSimulateFallingBlocks;
+ bool m_PreSimulateWater;
+ bool m_PreSimulateLava;
+
// Drops hanging sand and gravel down to the ground, recalculates heightmap
void CollapseSandGravel(
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
From 4dd858f8997488e2252f5a04df9df1654a70d67f Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 29 Jul 2014 17:45:55 +0200
Subject: [PATCH 026/751] Added a cMojangAPI class for PlayerName -> UUID
lookups, with cache.
The cache is persisted into a SQLite DB file on server shutdown.
---
src/Bindings/ManualBindings.cpp | 2 +-
src/CMakeLists.txt | 4 +-
src/Protocol/Authenticator.cpp | 216 +---------------
src/Protocol/Authenticator.h | 27 +-
src/Protocol/CMakeLists.txt | 2 +
src/Protocol/MojangAPI.cpp | 446 ++++++++++++++++++++++++++++++++
src/Protocol/MojangAPI.h | 102 ++++++++
src/Root.cpp | 1 +
src/Root.h | 3 +
9 files changed, 564 insertions(+), 239 deletions(-)
create mode 100644 src/Protocol/MojangAPI.cpp
create mode 100644 src/Protocol/MojangAPI.h
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 28ee00b36..6d69e2595 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2189,7 +2189,7 @@ static int tolua_cClientHandle_GetUUIDsFromPlayerNames(lua_State * L)
lua_newtable(L); // stack index 3
// Get the UUIDs:
- AStringVector UUIDs = cRoot::Get()->GetAuthenticator().GetUUIDsFromPlayerNames(PlayerNames);
+ AStringVector UUIDs = cRoot::Get()->GetMojangAPI().GetUUIDsFromPlayerNames(PlayerNames);
if (UUIDs.size() != PlayerNames.size())
{
// A hard error has occured while processing the request, no UUIDs were returned. Return an empty table:
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 29337cb2e..1d1c33088 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -138,6 +138,8 @@ SET (HDRS
XMLParser.h)
include_directories(".")
+include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../lib/sqlite")
+include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../lib/SQLiteCpp/include")
if (NOT MSVC)
# Bindings need to reference other folders, so they are done here instead
@@ -311,4 +313,4 @@ endif ()
if (WIN32)
target_link_libraries(${EXECUTABLE} expat tolualib ws2_32.lib Psapi.lib)
endif()
-target_link_libraries(${EXECUTABLE} luaexpat iniFile jsoncpp polarssl zlib sqlite lua)
+target_link_libraries(${EXECUTABLE} luaexpat iniFile jsoncpp polarssl zlib sqlite lua SQLiteCpp)
diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp
index 75721589f..e5d16cf10 100644
--- a/src/Protocol/Authenticator.cpp
+++ b/src/Protocol/Authenticator.cpp
@@ -2,6 +2,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Authenticator.h"
+#include "MojangAPI.h"
#include "../Root.h"
#include "../Server.h"
#include "../ClientHandle.h"
@@ -17,76 +18,11 @@
#define DEFAULT_AUTH_SERVER "sessionserver.mojang.com"
#define DEFAULT_AUTH_ADDRESS "/session/minecraft/hasJoined?username=%USERNAME%&serverId=%SERVERID%"
-#define DEFAULT_NAME_TO_UUID_SERVER "api.mojang.com"
-#define DEFAULT_NAME_TO_UUID_ADDRESS "/profiles/minecraft"
-
-/** This is the data of the root certs for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert:
-Downloaded from http://certs.starfieldtech.com/repository/ */
-static const AString StarfieldCACert()
-{
- return AString(
- // G2 cert
- "-----BEGIN CERTIFICATE-----\n"
- "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n"
- "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n"
- "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n"
- "ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n"
- "MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n"
- "b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n"
- "aG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZp\n"
- "Y2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n"
- "ggEBAL3twQP89o/8ArFvW59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMg\n"
- "nLRJdzIpVv257IzdIvpy3Cdhl+72WoTsbhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1\n"
- "HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNkN3mSwOxGXn/hbVNMYq/N\n"
- "Hwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7NfZTD4p7dN\n"
- "dloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0\n"
- "HZbUJtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAO\n"
- "BgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0G\n"
- "CSqGSIb3DQEBCwUAA4IBAQARWfolTwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjU\n"
- "sHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx4mcujJUDJi5DnUox9g61DLu3\n"
- "4jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUwF5okxBDgBPfg\n"
- "8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K\n"
- "pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1\n"
- "mMpYjn0q7pBZc2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0\n"
- "-----END CERTIFICATE-----\n\n"
- // Original (G1) cert:
- "-----BEGIN CERTIFICATE-----\n"
- "MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzEl\n"
- "MCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMp\n"
- "U3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQw\n"
- "NjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBoMQswCQYDVQQGEwJVUzElMCMGA1UE\n"
- "ChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZp\n"
- "ZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqGSIb3\n"
- "DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf\n"
- "8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN\n"
- "+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0\n"
- "X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa\n"
- "K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA\n"
- "1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G\n"
- "A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR\n"
- "zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0\n"
- "YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD\n"
- "bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w\n"
- "DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3\n"
- "L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D\n"
- "eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl\n"
- "xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp\n"
- "VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n"
- "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n"
- "-----END CERTIFICATE-----\n"
- );
-}
-
-
-
-
cAuthenticator::cAuthenticator(void) :
super("cAuthenticator"),
m_Server(DEFAULT_AUTH_SERVER),
m_Address(DEFAULT_AUTH_ADDRESS),
- m_NameToUUIDServer(DEFAULT_NAME_TO_UUID_SERVER),
- m_NameToUUIDAddress(DEFAULT_NAME_TO_UUID_ADDRESS),
m_ShouldAuthenticate(true)
{
}
@@ -109,8 +45,6 @@ void cAuthenticator::ReadINI(cIniFile & IniFile)
m_Server = IniFile.GetValueSet ("Authentication", "Server", DEFAULT_AUTH_SERVER);
m_Address = IniFile.GetValueSet ("Authentication", "Address", DEFAULT_AUTH_ADDRESS);
m_ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true);
- m_NameToUUIDServer = IniFile.GetValueSet ("Authentication", "NameToUUIDServer", DEFAULT_NAME_TO_UUID_SERVER);
- m_NameToUUIDAddress = IniFile.GetValueSet ("Authentication", "NameToUUIDAddress", DEFAULT_NAME_TO_UUID_ADDRESS);
}
@@ -157,93 +91,6 @@ void cAuthenticator::Stop(void)
-AStringVector cAuthenticator::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames)
-{
- AStringVector res;
-
- // Create the request body - a JSON containing all the playernames:
- Json::Value root;
- for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr)
- {
- Json::Value req(*itr);
- root.append(req);
- } // for itr - a_PlayerNames[]
- Json::FastWriter Writer;
- AString RequestBody = Writer.write(root);
-
- // Create the HTTP request:
- AString Request;
- Request += "POST " + m_NameToUUIDAddress + " HTTP/1.1\r\n";
- Request += "Host: " + m_NameToUUIDServer + "\r\n";
- Request += "User-Agent: MCServer\r\n";
- Request += "Connection: close\r\n";
- Request += "Content-Type: application/json\r\n";
- Request += Printf("Content-Length: %u\r\n", (unsigned)RequestBody.length());
- Request += "\r\n";
- Request += RequestBody;
-
- // Get the response from the server:
- AString Response;
- if (!SecureGetFromAddress(StarfieldCACert(), m_NameToUUIDServer, Request, Response))
- {
- return res;
- }
-
- // Check the HTTP status line:
- const AString Prefix("HTTP/1.1 200 OK");
- AString HexDump;
- if (Response.compare(0, Prefix.size(), Prefix))
- {
- LOGINFO("%s failed: bad HTTP status line received", __FUNCTION__);
- LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
- return res;
- }
-
- // Erase the HTTP headers from the response:
- size_t idxHeadersEnd = Response.find("\r\n\r\n");
- if (idxHeadersEnd == AString::npos)
- {
- LOGINFO("%s failed: bad HTTP response header received", __FUNCTION__);
- LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
- return res;
- }
- Response.erase(0, idxHeadersEnd + 4);
-
- // Parse the returned string into Json:
- Json::Reader reader;
- if (!reader.parse(Response, root, false) || !root.isArray())
- {
- LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON!", __FUNCTION__);
- LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
- return res;
- }
-
- // Fill in the resulting array; do not expect to get the UUIDs in the same order as the inputs:
- size_t len = a_PlayerNames.size();
- size_t JsonCount = root.size();
- res.resize(len);
- for (size_t idx = 0; idx < len; idx++) // For each input username...
- {
- const AString & InputName = a_PlayerNames[idx];
- for (size_t IdxJson = 0; IdxJson < JsonCount; ++IdxJson)
- {
- Json::Value & Val = root[IdxJson];
- AString JsonName = Val.get("name", "").asString();
- if (NoCaseCompare(JsonName, InputName) == 0)
- {
- res[idx] = Val.get("id", "").asString();
- break;
- }
- } // for IdxJson - root[]
- } // for idx - a_PlayerNames[] / res[]
-
- return res;
-}
-
-
-
-
-
void cAuthenticator::Execute(void)
{
for (;;)
@@ -286,62 +133,6 @@ void cAuthenticator::Execute(void)
-bool cAuthenticator::SecureGetFromAddress(const AString & a_CACerts, const AString & a_ExpectedPeerName, const AString & a_Data, AString & a_Response)
-{
- // Connect the socket:
- cBlockingSslClientSocket Socket;
- Socket.SetTrustedRootCertsFromString(a_CACerts, a_ExpectedPeerName);
- if (!Socket.Connect(a_ExpectedPeerName, 443))
- {
- LOGWARNING("cAuthenticator: Can't connect to %s: %s", a_ExpectedPeerName.c_str(), Socket.GetLastErrorText().c_str());
- return false;
- }
-
- if (!Socket.Send(a_Data.c_str(), a_Data.size()))
- {
- LOGWARNING("cAuthenticator: Writing SSL data failed: %s", Socket.GetLastErrorText().c_str());
- return false;
- }
-
- // Read the HTTP response:
- int ret;
- unsigned char buf[1024];
-
- for (;;)
- {
- ret = Socket.Receive(buf, sizeof(buf));
-
- if ((ret == POLARSSL_ERR_NET_WANT_READ) || (ret == POLARSSL_ERR_NET_WANT_WRITE))
- {
- // This value should never be returned, it is handled internally by cBlockingSslClientSocket
- LOGWARNING("cAuthenticator: SSL reading failed internally");
- return false;
- }
- if (ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY)
- {
- break;
- }
- if (ret < 0)
- {
- LOGWARNING("cAuthenticator: SSL reading failed: -0x%x", -ret);
- return false;
- }
- if (ret == 0)
- {
- break;
- }
-
- a_Response.append((const char *)buf, (size_t)ret);
- }
-
- Socket.Disconnect();
- return true;
-}
-
-
-
-
-
bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID, Json::Value & a_Properties)
{
LOGD("Trying to authenticate user %s", a_UserName.c_str());
@@ -359,7 +150,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
Request += "\r\n";
AString Response;
- if (!SecureGetFromAddress(StarfieldCACert(), m_Server, Request, Response))
+ if (!cMojangAPI::SecureRequest(m_Server, Request, Response))
{
return false;
}
@@ -399,6 +190,9 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
a_UserName = root.get("name", "Unknown").asString();
a_UUID = root.get("id", "").asString();
a_Properties = root["properties"];
+
+ // Store the player's UUID in the NameToUUID map in MojangAPI:
+ cRoot::Get()->GetMojangAPI().AddPlayerNameToUUIDMapping(a_UserName, a_UUID);
// If the UUID doesn't contain the dashes, insert them at the proper places:
if (a_UUID.size() == 32)
diff --git a/src/Protocol/Authenticator.h b/src/Protocol/Authenticator.h
index 82ecb1f7a..853eff535 100644
--- a/src/Protocol/Authenticator.h
+++ b/src/Protocol/Authenticator.h
@@ -11,8 +11,6 @@
#pragma once
-#ifndef CAUTHENTICATOR_H_INCLUDED
-#define CAUTHENTICATOR_H_INCLUDED
#include "../OSSupport/IsThread.h"
@@ -53,12 +51,6 @@ public:
/** Stops the authenticator thread. The thread may be started and stopped repeatedly */
void Stop(void);
- /** Converts the player names into UUIDs.
- a_PlayerName[idx] will be converted to UUID and returned as idx-th value
- The UUID will be empty on error.
- Blocking operation, do not use in world-tick thread! */
- AStringVector GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName);
-
private:
class cUser
@@ -91,34 +83,17 @@ private:
For example "/session/minecraft/hasJoined?username=%USERNAME%&serverId=%SERVERID%". */
AString m_Address;
- /** The server to connect to when converting player names to UUIDs. For example "api.mojang.com". */
- AString m_NameToUUIDServer;
-
- /** The URL to use for converting player names to UUIDs, without server part.
- For example "/profiles/page/1". */
- AString m_NameToUUIDAddress;
-
AString m_PropertiesAddress;
bool m_ShouldAuthenticate;
/** cIsThread override: */
virtual void Execute(void) override;
- /** Connects to a hostname using SSL, sends given data, and sets the response, returning whether all was successful or not */
- bool SecureGetFromAddress(const AString & a_CACerts, const AString & a_ExpectedPeerName, const AString & a_Request, AString & a_Response);
-
/** Returns true if the user authenticated okay, false on error
- Sets the username, UUID, and properties (i.e. skin) fields
- */
+ Returns the case-corrected username, UUID, and properties (eg. skin). */
bool AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID, Json::Value & a_Properties);
};
-
-#endif // CAUTHENTICATOR_H_INCLUDED
-
-
-
-
diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt
index ae447ce54..1ba66ff1f 100644
--- a/src/Protocol/CMakeLists.txt
+++ b/src/Protocol/CMakeLists.txt
@@ -7,6 +7,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
SET (SRCS
Authenticator.cpp
ChunkDataSerializer.cpp
+ MojangAPI.cpp
Protocol125.cpp
Protocol132.cpp
Protocol14x.cpp
@@ -18,6 +19,7 @@ SET (SRCS
SET (HDRS
Authenticator.h
ChunkDataSerializer.h
+ MojangAPI.h
Protocol.h
Protocol125.h
Protocol132.h
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
new file mode 100644
index 000000000..05f9c09a7
--- /dev/null
+++ b/src/Protocol/MojangAPI.cpp
@@ -0,0 +1,446 @@
+
+// MojangAPI.cpp
+
+// Implements the cMojangAPI class representing the various API points provided by Mojang's webservices, and a cache for their results
+
+#include "Globals.h"
+#include "MojangAPI.h"
+#include "SQLiteCpp/Database.h"
+#include "SQLiteCpp/Statement.h"
+#include "inifile/iniFile.h"
+#include "json/json.h"
+#include "PolarSSL++/BlockingSslClientSocket.h"
+
+
+
+
+
+/** The maximum age for items to be kept in the cache. Any item older than this will be removed. */
+const Int64 MAX_AGE = 7 * 24 * 60 * 60; // 7 days ago
+
+
+
+
+
+#define DEFAULT_NAME_TO_UUID_SERVER "api.mojang.com"
+#define DEFAULT_NAME_TO_UUID_ADDRESS "/profiles/minecraft"
+
+
+
+
+
+/** This is the data of the root certs for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert:
+Downloaded from http://certs.starfieldtech.com/repository/ */
+static const AString & StarfieldCACert(void)
+{
+ static const AString Cert(
+ // G2 cert
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n"
+ "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n"
+ "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n"
+ "ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n"
+ "MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n"
+ "b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n"
+ "aG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZp\n"
+ "Y2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n"
+ "ggEBAL3twQP89o/8ArFvW59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMg\n"
+ "nLRJdzIpVv257IzdIvpy3Cdhl+72WoTsbhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1\n"
+ "HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNkN3mSwOxGXn/hbVNMYq/N\n"
+ "Hwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7NfZTD4p7dN\n"
+ "dloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0\n"
+ "HZbUJtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAO\n"
+ "BgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0G\n"
+ "CSqGSIb3DQEBCwUAA4IBAQARWfolTwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjU\n"
+ "sHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx4mcujJUDJi5DnUox9g61DLu3\n"
+ "4jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUwF5okxBDgBPfg\n"
+ "8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K\n"
+ "pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1\n"
+ "mMpYjn0q7pBZc2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0\n"
+ "-----END CERTIFICATE-----\n\n"
+ // Original (G1) cert:
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzEl\n"
+ "MCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMp\n"
+ "U3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQw\n"
+ "NjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBoMQswCQYDVQQGEwJVUzElMCMGA1UE\n"
+ "ChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZp\n"
+ "ZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqGSIb3\n"
+ "DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf\n"
+ "8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN\n"
+ "+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0\n"
+ "X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa\n"
+ "K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA\n"
+ "1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G\n"
+ "A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR\n"
+ "zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0\n"
+ "YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD\n"
+ "bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w\n"
+ "DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3\n"
+ "L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D\n"
+ "eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl\n"
+ "xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp\n"
+ "VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n"
+ "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n"
+ "-----END CERTIFICATE-----\n"
+ );
+
+ return Cert;
+}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// cMojangAPI:
+
+cMojangAPI::cMojangAPI(void) :
+ m_NameToUUIDServer(DEFAULT_NAME_TO_UUID_SERVER),
+ m_NameToUUIDAddress(DEFAULT_NAME_TO_UUID_ADDRESS)
+{
+}
+
+
+
+
+
+cMojangAPI::~cMojangAPI()
+{
+ SaveCachesToDisk();
+}
+
+
+
+
+
+void cMojangAPI::Start(cIniFile & a_SettingsIni)
+{
+ m_NameToUUIDServer = a_SettingsIni.GetValueSet("Authentication", "NameToUUIDServer", DEFAULT_NAME_TO_UUID_SERVER);
+ m_NameToUUIDAddress = a_SettingsIni.GetValueSet("Authentication", "NameToUUIDAddress", DEFAULT_NAME_TO_UUID_ADDRESS);
+ LoadCachesFromDisk();
+}
+
+
+
+
+
+AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames)
+{
+ // Convert all playernames to lowercase:
+ AStringVector PlayerNames;
+ for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr)
+ {
+ AString Lower(*itr);
+ PlayerNames.push_back(StrToLower(Lower));
+ } // for itr - a_PlayerNames[]
+
+ // Request the cache to populate any names not yet contained:
+ CacheNamesToUUIDs(PlayerNames);
+
+ // Retrieve from cache:
+ size_t idx = 0;
+ AStringVector res;
+ res.resize(PlayerNames.size());
+ cCSLock Lock(m_CSNameToUUID);
+ for (AStringVector::const_iterator itr = PlayerNames.begin(), end = PlayerNames.end(); itr != end; ++itr, ++idx)
+ {
+ cNameToUUIDMap::const_iterator itrN = m_NameToUUID.find(*itr);
+ if (itrN != m_NameToUUID.end())
+ {
+ res[idx] = itrN->second.m_UUID;
+ }
+ } // for itr - PlayerNames[]
+ return res;
+}
+
+
+
+
+
+void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID)
+{
+ AString lcName(a_PlayerName);
+ Int64 Now = time(NULL);
+ cCSLock Lock(m_CSNameToUUID);
+ m_NameToUUID[StrToLower(lcName)] = sUUIDRecord(a_PlayerName, a_UUID, Now);
+}
+
+
+
+
+
+bool cMojangAPI::SecureRequest(const AString & a_ServerName, const AString & a_Request, AString & a_Response)
+{
+ // Connect the socket:
+ cBlockingSslClientSocket Socket;
+ Socket.SetTrustedRootCertsFromString(StarfieldCACert(), a_ServerName);
+ if (!Socket.Connect(a_ServerName, 443))
+ {
+ LOGWARNING("%s: Can't connect to %s: %s", __FUNCTION__, a_ServerName.c_str(), Socket.GetLastErrorText().c_str());
+ return false;
+ }
+
+ if (!Socket.Send(a_Request.c_str(), a_Request.size()))
+ {
+ LOGWARNING("%s: Writing SSL data failed: %s", __FUNCTION__, Socket.GetLastErrorText().c_str());
+ return false;
+ }
+
+ // Read the HTTP response:
+ int ret;
+ unsigned char buf[1024];
+
+ for (;;)
+ {
+ ret = Socket.Receive(buf, sizeof(buf));
+
+ if ((ret == POLARSSL_ERR_NET_WANT_READ) || (ret == POLARSSL_ERR_NET_WANT_WRITE))
+ {
+ // This value should never be returned, it is handled internally by cBlockingSslClientSocket
+ LOGWARNING("%s: SSL reading failed internally", __FUNCTION__);
+ return false;
+ }
+ if (ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY)
+ {
+ break;
+ }
+ if (ret < 0)
+ {
+ LOGWARNING("%s: SSL reading failed: -0x%x", __FUNCTION__, -ret);
+ return false;
+ }
+ if (ret == 0)
+ {
+ break;
+ }
+
+ a_Response.append((const char *)buf, (size_t)ret);
+ }
+
+ Socket.Disconnect();
+ return true;
+}
+
+
+
+
+
+AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
+{
+ switch (a_UUID.size())
+ {
+ case 32: return a_UUID;
+
+ case 36:
+ {
+ AString res;
+ // TODO
+ return res;
+ }
+ }
+ LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str());
+ return "";
+}
+
+
+
+
+
+AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID)
+{
+ switch (a_UUID.size())
+ {
+ case 36: return a_UUID;
+
+ case 32:
+ {
+ AString res;
+ // TODO
+ return res;
+ }
+ }
+ LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str());
+ return "";
+}
+
+
+
+
+
+void cMojangAPI::LoadCachesFromDisk(void)
+{
+ try
+ {
+ // Open up the SQLite DB:
+ SQLite::Database db("NameToUUID.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+ db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)");
+
+ // Clean up old entries:
+ {
+ SQLite::Statement stmt(db, "DELETE FROM PlayerNameToUUID WHERE DateTime < ?");
+ Int64 LimitDateTime = time(NULL) - MAX_AGE;
+ stmt.bind(1, LimitDateTime);
+ stmt.exec();
+ }
+
+ // Retrieve all remaining entries::
+ SQLite::Statement stmt(db, "SELECT PlayerName, UUID, DateTime FROM PlayerNameToUUID");
+ while (stmt.executeStep())
+ {
+ AString PlayerName = stmt.getColumn(0);
+ AString UUID = stmt.getColumn(1);
+ Int64 DateTime = stmt.getColumn(2);
+ AString lcPlayerName = PlayerName;
+ m_NameToUUID[StrToLower(lcPlayerName)] = sUUIDRecord(PlayerName, UUID, DateTime);
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGINFO("Loading MojangAPI cache failed: %s", ex.what());
+ }
+}
+
+
+
+
+
+void cMojangAPI::SaveCachesToDisk(void)
+{
+ try
+ {
+ // Open up the SQLite DB:
+ SQLite::Database db("NameToUUID.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+ db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)");
+
+ // Remove all entries:
+ db.exec("DELETE FROM PlayerNameToUUID");
+
+ // Save all cache entries:
+ SQLite::Statement stmt(db, "INSERT INTO PlayerNameToUUID(PlayerName, UUID, DateTime) VALUES (?, ?, ?)");
+ Int64 LimitDateTime = time(NULL) - MAX_AGE;
+ cCSLock Lock(m_CSNameToUUID);
+ for (cNameToUUIDMap::const_iterator itr = m_NameToUUID.begin(), end = m_NameToUUID.end(); itr != end; ++itr)
+ {
+ if (itr->second.m_DateTime < LimitDateTime)
+ {
+ // This item is too old, do not save
+ continue;
+ }
+ stmt.bind(1, itr->second.m_PlayerName);
+ stmt.bind(2, itr->second.m_UUID);
+ stmt.bind(3, itr->second.m_DateTime);
+ stmt.exec();
+ stmt.reset();
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGINFO("Saving MojangAPI cache failed: %s", ex.what());
+ }
+}
+
+
+
+
+
+void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
+{
+ // Create a list of names to query, by removing those that are already cached:
+ AStringVector NamesToQuery;
+ NamesToQuery.reserve(a_PlayerNames.size());
+ {
+ cCSLock Lock(m_CSNameToUUID);
+ for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr)
+ {
+ if (m_NameToUUID.find(*itr) == m_NameToUUID.end())
+ {
+ NamesToQuery.push_back(*itr);
+ }
+ } // for itr - a_PlayerNames[]
+ } // Lock(m_CSNameToUUID)
+
+ while (!NamesToQuery.empty())
+ {
+ // Create the request body - a JSON containing up to 100 playernames:
+ Json::Value root;
+ int Count = 0;
+ AStringVector::iterator itr = NamesToQuery.begin(), end = NamesToQuery.end();
+ for (; (itr != end) && (Count < 100); ++itr, ++Count)
+ {
+ Json::Value req(*itr);
+ root.append(req);
+ } // for itr - a_PlayerNames[]
+ NamesToQuery.erase(NamesToQuery.begin(), itr);
+ Json::FastWriter Writer;
+ AString RequestBody = Writer.write(root);
+
+ // Create the HTTP request:
+ AString Request;
+ Request += "POST " + m_NameToUUIDAddress + " HTTP/1.0\r\n";
+ Request += "Host: " + m_NameToUUIDServer + "\r\n";
+ Request += "User-Agent: MCServer\r\n";
+ Request += "Connection: close\r\n";
+ Request += "Content-Type: application/json\r\n";
+ Request += Printf("Content-Length: %u\r\n", (unsigned)RequestBody.length());
+ Request += "\r\n";
+ Request += RequestBody;
+
+ // Get the response from the server:
+ AString Response;
+ if (!SecureRequest(m_NameToUUIDServer, Request, Response))
+ {
+ continue;
+ }
+
+ // Check the HTTP status line:
+ const AString Prefix("HTTP/1.1 200 OK");
+ AString HexDump;
+ if (Response.compare(0, Prefix.size(), Prefix))
+ {
+ LOGINFO("%s failed: bad HTTP status line received", __FUNCTION__);
+ LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ continue;
+ }
+
+ // Erase the HTTP headers from the response:
+ size_t idxHeadersEnd = Response.find("\r\n\r\n");
+ if (idxHeadersEnd == AString::npos)
+ {
+ LOGINFO("%s failed: bad HTTP response header received", __FUNCTION__);
+ LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ continue;
+ }
+ Response.erase(0, idxHeadersEnd + 4);
+
+ // Parse the returned string into Json:
+ Json::Reader reader;
+ if (!reader.parse(Response, root, false) || !root.isArray())
+ {
+ LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON!", __FUNCTION__);
+ LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ continue;
+ }
+
+ // Store the returned results into cache:
+ size_t JsonCount = root.size();
+ Int64 Now = time(NULL);
+ cCSLock Lock(m_CSNameToUUID);
+ for (size_t idx = 0; idx < JsonCount; ++idx)
+ {
+ Json::Value & Val = root[idx];
+ AString JsonName = Val.get("name", "").asString();
+ AString JsonUUID = Val.get("id", "").asString();
+ if (JsonUUID.empty())
+ {
+ continue;
+ }
+ AString lcName = JsonName;
+ m_NameToUUID[StrToLower(lcName)] = sUUIDRecord(JsonName, JsonUUID, Now);
+ } // for idx - root[]
+ } // while (!NamesToQuery.empty())
+}
+
+
+
+
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
new file mode 100644
index 000000000..789fdf818
--- /dev/null
+++ b/src/Protocol/MojangAPI.h
@@ -0,0 +1,102 @@
+
+// MojangAPI.h
+
+// Declares the cMojangAPI class representing the various API points provided by Mojang's webservices, and a cache for their results
+
+
+
+
+
+#pragma once
+
+#include
+
+
+
+
+
+class cMojangAPI
+{
+public:
+ cMojangAPI(void);
+ ~cMojangAPI();
+
+ /** Initializes the API; reads the settings from the specified ini file.
+ Loads cached results from disk. */
+ void Start(cIniFile & a_SettingsIni);
+
+ /** Connects to the specified server using SSL, sends the given request and receives the response.
+ Checks Mojang certificates using the hard-coded Starfield root CA certificate.
+ Returns true if all was successful, false on failure. */
+ static bool SecureRequest(const AString & a_ServerName, const AString & a_Request, AString & a_Response);
+
+ /** Converts the given UUID to its short form (32 bytes, no dashes).
+ Logs a warning and returns empty string if not a UUID. */
+ static AString MakeUUIDShort(const AString & a_UUID);
+
+ /** Converts the given UUID to its dashed form (36 bytes, 4 dashes).
+ Logs a warning and returns empty string if not a UUID. */
+ static AString MakeUUIDDashed(const AString & a_UUID);
+
+ /** Converts the player names into UUIDs.
+ a_PlayerName[idx] will be converted to UUID and returned as idx-th value
+ The UUID will be empty on error.
+ Blocking operation, do not use in world-tick thread! */
+ AStringVector GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName);
+
+ /** Called by the Authenticator to add a PlayerName -> UUID mapping that it has received from
+ authenticating a user. This adds the cache item and "refreshes" it if existing, adjusting its datetime
+ stamp to now. */
+ void AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID);
+
+protected:
+ struct sUUIDRecord
+ {
+ AString m_PlayerName; // Case-correct playername
+ AString m_UUID;
+ Int64 m_DateTime; // UNIXtime of the UUID lookup
+
+ sUUIDRecord(void) :
+ m_UUID(),
+ m_DateTime(time(NULL))
+ {
+ }
+
+ sUUIDRecord(const AString & a_PlayerName, const AString & a_UUID, Int64 a_DateTime) :
+ m_PlayerName(a_PlayerName),
+ m_UUID(a_UUID),
+ m_DateTime(a_DateTime)
+ {
+ }
+ };
+ typedef std::map cNameToUUIDMap; // maps Lowercased PlayerName to sUUIDRecord
+
+ /** The server to connect to when converting player names to UUIDs. For example "api.mojang.com". */
+ AString m_NameToUUIDServer;
+
+ /** The URL to use for converting player names to UUIDs, without server part.
+ For example "/profiles/page/1". */
+ AString m_NameToUUIDAddress;
+
+ /** Cache for the Name-to-UUID lookups. The map key is expected lowercased. Protected by m_CSNameToUUID. */
+ cNameToUUIDMap m_NameToUUID;
+
+ /** Protects m_NameToUUID against simultaneous multi-threaded access. */
+ cCriticalSection m_CSNameToUUID;
+
+
+ /** Loads the caches from a disk storage. */
+ void LoadCachesFromDisk(void);
+
+ /** Saves the caches to a disk storage. */
+ void SaveCachesToDisk(void);
+
+ /** Makes sure all specified names are in the cache. Downloads any missing ones from Mojang API servers.
+ Names that are not valid are not added into the cache.
+ ASSUMEs that a_PlayerNames contains lowercased player names. */
+ void CacheNamesToUUIDs(const AStringVector & a_PlayerNames);
+} ;
+
+
+
+
diff --git a/src/Root.cpp b/src/Root.cpp
index b03a13382..7d4fb80fd 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -145,6 +145,7 @@ void cRoot::Start(void)
}
LOG("Starting server...");
+ m_MojangAPI.Start(IniFile); // Mojang API needs to be started before plugins, so that plugins may use it for DB upgrades on server init
if (!m_Server->InitServer(IniFile))
{
LOGERROR("Failure starting server, aborting...");
diff --git a/src/Root.h b/src/Root.h
index 08aafe3c9..92a60a10d 100644
--- a/src/Root.h
+++ b/src/Root.h
@@ -2,6 +2,7 @@
#pragma once
#include "Protocol/Authenticator.h"
+#include "Protocol/MojangAPI.h"
#include "HTTPServer/HTTPServer.h"
#include "Defines.h"
@@ -78,6 +79,7 @@ public:
cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export
cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
+ cMojangAPI & GetMojangAPI (void) { return m_MojangAPI; }
/** Queues a console command for execution through the cServer class.
The command will be executed in the tick thread
@@ -182,6 +184,7 @@ private:
cWebAdmin * m_WebAdmin;
cPluginManager * m_PluginManager;
cAuthenticator m_Authenticator;
+ cMojangAPI m_MojangAPI;
cHTTPServer m_HTTPServer;
cMCLogger * m_Log;
From 6476bd0e2ee7e128e3eaa56159f169f0a53736ff Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 13:44:03 +0200
Subject: [PATCH 027/751] Exported cMojangAPI to Lua.
---
MCServer/Plugins/APIDump/APIDesc.lua | 27 ++++++++++++++++++++++++++-
src/Bindings/AllToLua.pkg | 1 +
src/Bindings/ManualBindings.cpp | 9 ++++++---
src/Protocol/MojangAPI.h | 13 ++++++++++++-
src/Root.h | 2 +-
5 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index f29c47338..e5114784e 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -529,7 +529,6 @@ end
GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client. Note that this may be nil, for example if the player object is not yet spawned." },
GetUniqueID = { Params = "", Return = "number", Notes = "Returns the UniqueID of the client used to identify the client in the server" },
GetUUID = { Params = "", Return = "string", Notes = "Returns the authentication-based UUID of the client. This UUID should be used to identify the player when persisting any player-related data." },
- GetUUIDsFromPlayerNames = { Params = "PlayerNames", Return = "table", Notes = "(STATIC) Returns a table that contains the map, 'PlayerName' -> 'UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. Queries the Mojang servers for the results. WARNING: Do NOT use this function while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely. NOTE: Mojang API has a limit of 100 names per query and 600 queries per 10 minutes (may change)" },
GetUsername = { Params = "", Return = "string", Notes = "Returns the username that the client has provided" },
GetViewDistance = { Params = "", Return = "number", Notes = "Returns the viewdistance (number of chunks loaded for the player in each direction)" },
HasPluginChannel = { Params = "ChannelName", Return = "bool", Notes = "Returns true if the client has registered to receive messages on the specified plugin channel." },
@@ -1607,6 +1606,31 @@ a_Player:OpenWindow(Window);
}, -- cMapManager
+ cMojangAPI =
+ {
+ Desc = [[
+ Provides interface to various API functions that Mojang provides through their servers. Note that
+ some of these calls will wait for a response from the network, and so shouldn't be used while the
+ server is fully running (or at least when there are players connected) to avoid percepted lag.
+
+ Some functions are static and do not require an instance to be called. For others, you need to get
+ the singleton instance of this class using {{cRoot}}'s GetMojangAPI() function.
+
+ Mojang uses two formats for UUIDs, short and dashed. MCServer works with short UUIDs internally, but
+ will convert to dashed UUIDs where needed - in the protocol login for example. The MakeUUIDShort()
+ and MakeUUIDDashed() functions are provided for plugins to use for conversion between the two
+ formats.
+ ]],
+ Functions =
+ {
+ AddPlayerNameToUUIDMapping = { Params = "PlayerName, UUID", Return = "", Notes = "Adds the specified PlayerName-to-UUID mapping into the cache, with current timestamp." },
+ GetUUIDsFromPlayerNames = { Params = "PlayerNames", Return = "table", Notes = "Returns a table that contains the map, 'PlayerName' -> 'UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. Queries the Mojang servers for the results. WARNING: Do NOT use this function while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
+ MakeUUIDDashed = { Params = "UUID", Return = "DashedUUID", Notes = "(STATIC) Converts the UUID to a dashed format (\"01234567-8901-2345-6789-012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
+ MakeUUIDShort = { Params = "UUID", Return = "ShortUUID", Notes = "(STATIC) Converts the UUID to a short format (without dashes, \"01234567890123456789012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
+ },
+
+ },
+
cMonster =
{
Desc = [[
@@ -2002,6 +2026,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
GetFurnaceFuelBurnTime = { Params = "{{cItem|Fuel}}", Return = "number", Notes = "(STATIC) Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel." },
GetFurnaceRecipe = { Params = "{{cItem|InItem}}", Return = "{{cItem|OutItem}}, NumTicks, {{cItem|InItem}}", Notes = "(STATIC) Returns the furnace recipe for smelting the specified input. If a recipe is found, returns the smelted result, the number of ticks required for the smelting operation, and the input consumed (note that MCServer supports smelting M items into N items and different smelting rates). If no recipe is found, returns no value." },
GetGroupManager = { Params = "", Return = "{{cGroupManager|cGroupManager}}", Notes = "Returns the cGroupManager object." },
+ GetMojangAPI = { Params = "", Return = "{{cMojangAPI}}", Notes = "Returns the {{cMojangAPI}} object." },
GetPhysicalRAMUsage = { Params = "", Return = "number", Notes = "Returns the amount of physical RAM that the entire MCServer process is using, in KiB. Negative if the OS doesn't support this query." },
GetPluginManager = { Params = "", Return = "{{cPluginManager|cPluginManager}}", Notes = "Returns the cPluginManager object." },
GetPrimaryServerVersion = { Params = "", Return = "number", Notes = "Returns the servers primary server version." },
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 1e5dfd2fe..d3e3f5b45 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -77,6 +77,7 @@ $cfile "../Map.h"
$cfile "../MapManager.h"
$cfile "../Scoreboard.h"
$cfile "../Statistics.h"
+$cfile "../Protocol/MojangAPI.h"
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 6d69e2595..026a6bad5 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2157,11 +2157,11 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L)
-static int tolua_cClientHandle_GetUUIDsFromPlayerNames(lua_State * L)
+static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
{
cLuaState S(L);
if (
- !S.CheckParamUserTable(1, "cClientHandle") ||
+ !S.CheckParamUserTable(1, "cMojangAPI") ||
!S.CheckParamTable(2) ||
!S.CheckParamEnd(3)
)
@@ -3144,9 +3144,12 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE);
tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE);
tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage);
- tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cClientHandle_GetUUIDsFromPlayerNames);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "cMojangAPI");
+ tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cMojangAPI_GetUUIDsFromPlayerNames);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cItemGrid");
tolua_function(tolua_S, "GetSlotCoords", Lua_ItemGrid_GetSlotCoords);
tolua_endmodule(tolua_S);
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index 789fdf818..cc2902a19 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -15,9 +15,12 @@
+// tolua_begin
class cMojangAPI
{
public:
+ // tolua_end
+
cMojangAPI(void);
~cMojangAPI();
@@ -30,6 +33,8 @@ public:
Returns true if all was successful, false on failure. */
static bool SecureRequest(const AString & a_ServerName, const AString & a_Request, AString & a_Response);
+ // tolua_begin
+
/** Converts the given UUID to its short form (32 bytes, no dashes).
Logs a warning and returns empty string if not a UUID. */
static AString MakeUUIDShort(const AString & a_UUID);
@@ -38,16 +43,22 @@ public:
Logs a warning and returns empty string if not a UUID. */
static AString MakeUUIDDashed(const AString & a_UUID);
+ // tolua_end
+
/** Converts the player names into UUIDs.
a_PlayerName[idx] will be converted to UUID and returned as idx-th value
The UUID will be empty on error.
Blocking operation, do not use in world-tick thread! */
AStringVector GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName);
+ // tolua_begin
+
/** Called by the Authenticator to add a PlayerName -> UUID mapping that it has received from
authenticating a user. This adds the cache item and "refreshes" it if existing, adjusting its datetime
stamp to now. */
void AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID);
+
+ // tolua_end
protected:
struct sUUIDRecord
@@ -95,7 +106,7 @@ protected:
Names that are not valid are not added into the cache.
ASSUMEs that a_PlayerNames contains lowercased player names. */
void CacheNamesToUUIDs(const AStringVector & a_PlayerNames);
-} ;
+} ; // tolua_export
diff --git a/src/Root.h b/src/Root.h
index 92a60a10d..210c36ea9 100644
--- a/src/Root.h
+++ b/src/Root.h
@@ -79,7 +79,7 @@ public:
cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export
cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
- cMojangAPI & GetMojangAPI (void) { return m_MojangAPI; }
+ cMojangAPI & GetMojangAPI (void) { return m_MojangAPI; } // tolua_export
/** Queues a console command for execution through the cServer class.
The command will be executed in the tick thread
From 17a94b16ea6207fd5f38fbd309b4db0d92de0d31 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 13:52:51 +0200
Subject: [PATCH 028/751] MojangAPI: Implemented UUID shortening and dashing.
---
src/ClientHandle.cpp | 3 ++-
src/ClientHandle.h | 8 +++++++-
src/Protocol/Authenticator.cpp | 11 +----------
src/Protocol/MojangAPI.cpp | 34 +++++++++++++++++++++++++++-------
src/Protocol/Protocol17x.cpp | 6 +++---
5 files changed, 40 insertions(+), 22 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index e4ad218a2..3f81f0a29 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -233,13 +233,14 @@ AString cClientHandle::GenerateOfflineUUID(const AString & a_Username)
// This guarantees that they will never collide with an online UUID and can be distinguished.
// Proper format for a version 3 UUID is:
// xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B
+ // Note that we generate a short UUID (without the dashes)
// Generate an md5 checksum, and use it as base for the ID:
unsigned char MD5[16];
md5((const unsigned char *)a_Username.c_str(), a_Username.length(), MD5);
MD5[6] &= 0x0f; // Need to trim to 4 bits only...
MD5[8] &= 0x0f; // ... otherwise %01x overflows into two chars
- return Printf("%02x%02x%02x%02x-%02x%02x-3%01x%02x-8%01x%02x-%02x%02x%02x%02x%02x%02x",
+ return Printf("%02x%02x%02x%02x%02x%02x3%01x%02x8%01x%02x%02x%02x%02x%02x%02x%02x",
MD5[0], MD5[1], MD5[2], MD5[3],
MD5[4], MD5[5], MD5[6], MD5[7],
MD5[8], MD5[9], MD5[10], MD5[11],
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 50ed596d5..f2183a5ca 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -66,7 +66,9 @@ public:
cPlayer * GetPlayer(void) { return m_Player; } // tolua_export
+ /** Returns the player's UUID, as used by the protocol, in the short form (no dashes) */
const AString & GetUUID(void) const { return m_UUID; } // tolua_export
+
void SetUUID(const AString & a_UUID) { m_UUID = a_UUID; }
const Json::Value & GetProperties(void) const { return m_Properties; }
@@ -80,7 +82,7 @@ public:
/** Generates an UUID based on the player name provided.
This is used for the offline (non-auth) mode, when there's no UUID source.
Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same.
- Returns a 36-char UUID (with dashes). */
+ Returns a 32-char UUID (no dashes). */
static AString GenerateOfflineUUID(const AString & a_Username); // tolua_export
/** Returns true if the UUID is generated by online auth, false if it is an offline-generated UUID.
@@ -360,7 +362,11 @@ private:
int m_NumBlockChangeInteractionsThisTick;
static int s_ClientCount;
+
+ /** ID used for identification during authenticating. Assigned sequentially for each new instance. */
int m_UniqueID;
+
+ /** Contains the UUID used by Mojang to identify the player's account. Short UUID stored here (without dashes) */
AString m_UUID;
/** Set to true when the chunk where the player is is sent to the client. Used for spawning the player */
diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp
index e5d16cf10..160564d51 100644
--- a/src/Protocol/Authenticator.cpp
+++ b/src/Protocol/Authenticator.cpp
@@ -188,21 +188,12 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
return false;
}
a_UserName = root.get("name", "Unknown").asString();
- a_UUID = root.get("id", "").asString();
+ a_UUID = cMojangAPI::MakeUUIDShort(root.get("id", "").asString());
a_Properties = root["properties"];
// Store the player's UUID in the NameToUUID map in MojangAPI:
cRoot::Get()->GetMojangAPI().AddPlayerNameToUUIDMapping(a_UserName, a_UUID);
- // If the UUID doesn't contain the dashes, insert them at the proper places:
- if (a_UUID.size() == 32)
- {
- a_UUID.insert(8, "-");
- a_UUID.insert(13, "-");
- a_UUID.insert(18, "-");
- a_UUID.insert(23, "-");
- }
-
return true;
}
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 05f9c09a7..52afd71da 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -18,6 +18,9 @@
/** The maximum age for items to be kept in the cache. Any item older than this will be removed. */
const Int64 MAX_AGE = 7 * 24 * 60 * 60; // 7 days ago
+/** The maximum number of names to send in a single query */
+const int MAX_PER_QUERY = 100;
+
@@ -29,6 +32,7 @@ const Int64 MAX_AGE = 7 * 24 * 60 * 60; // 7 days ago
+
/** This is the data of the root certs for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert:
Downloaded from http://certs.starfieldtech.com/repository/ */
static const AString & StarfieldCACert(void)
@@ -161,9 +165,10 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player
void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID)
{
AString lcName(a_PlayerName);
+ AString UUID = MakeUUIDShort(a_UUID);
Int64 Now = time(NULL);
cCSLock Lock(m_CSNameToUUID);
- m_NameToUUID[StrToLower(lcName)] = sUUIDRecord(a_PlayerName, a_UUID, Now);
+ m_NameToUUID[StrToLower(lcName)] = sUUIDRecord(a_PlayerName, UUID, Now);
}
@@ -234,8 +239,14 @@ AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
case 36:
{
+ // Remove the dashes from the string:
AString res;
- // TODO
+ res.reserve(32);
+ res.append(a_UUID, 0, 8);
+ res.append(a_UUID, 9, 4);
+ res.append(a_UUID, 14, 4);
+ res.append(a_UUID, 19, 4);
+ res.append(a_UUID, 24, 12);
return res;
}
}
@@ -256,7 +267,16 @@ AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID)
case 32:
{
AString res;
- // TODO
+ res.reserve(36);
+ res.append(a_UUID, 0, 8);
+ res.push_back('-');
+ res.append(a_UUID, 8, 4);
+ res.push_back('-');
+ res.append(a_UUID, 12, 4);
+ res.push_back('-');
+ res.append(a_UUID, 16, 4);
+ res.push_back('-');
+ res.append(a_UUID, 20, 12);
return res;
}
}
@@ -362,11 +382,11 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
while (!NamesToQuery.empty())
{
- // Create the request body - a JSON containing up to 100 playernames:
+ // Create the request body - a JSON containing up to MAX_PER_QUERY playernames:
Json::Value root;
int Count = 0;
AStringVector::iterator itr = NamesToQuery.begin(), end = NamesToQuery.end();
- for (; (itr != end) && (Count < 100); ++itr, ++Count)
+ for (; (itr != end) && (Count < MAX_PER_QUERY); ++itr, ++Count)
{
Json::Value req(*itr);
root.append(req);
@@ -377,7 +397,7 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
// Create the HTTP request:
AString Request;
- Request += "POST " + m_NameToUUIDAddress + " HTTP/1.0\r\n";
+ Request += "POST " + m_NameToUUIDAddress + " HTTP/1.0\r\n"; // We need to use HTTP 1.0 because we don't handle Chunked transfer encoding
Request += "Host: " + m_NameToUUIDServer + "\r\n";
Request += "User-Agent: MCServer\r\n";
Request += "Connection: close\r\n";
@@ -430,7 +450,7 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
{
Json::Value & Val = root[idx];
AString JsonName = Val.get("name", "").asString();
- AString JsonUUID = Val.get("id", "").asString();
+ AString JsonUUID = MakeUUIDShort(Val.get("id", "").asString());
if (JsonUUID.empty())
{
continue;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index dadf82716..73aba167d 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -680,7 +680,7 @@ void cProtocol172::SendLoginSuccess(void)
{
cPacketizer Pkt(*this, 0x02); // Login success packet
- Pkt.WriteString(m_Client->GetUUID());
+ Pkt.WriteString(cMojangAPI::MakeUUIDDashed(m_Client->GetUUID()));
Pkt.WriteString(m_Client->GetUsername());
}
@@ -941,7 +941,7 @@ void cProtocol172::SendPlayerSpawn(const cPlayer & a_Player)
// Called to spawn another player for the client
cPacketizer Pkt(*this, 0x0c); // Spawn Player packet
Pkt.WriteVarInt(a_Player.GetUniqueID());
- Pkt.WriteString(a_Player.GetClientHandle()->GetUUID());
+ Pkt.WriteString(cMojangAPI::MakeUUIDDashed(a_Player.GetClientHandle()->GetUUID()));
Pkt.WriteString(a_Player.GetName());
Pkt.WriteFPInt(a_Player.GetPosX());
Pkt.WriteFPInt(a_Player.GetPosY());
@@ -3014,7 +3014,7 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player)
// Called to spawn another player for the client
cPacketizer Pkt(*this, 0x0c); // Spawn Player packet
Pkt.WriteVarInt(a_Player.GetUniqueID());
- Pkt.WriteString(a_Player.GetClientHandle()->GetUUID());
+ Pkt.WriteString(cMojangAPI::MakeUUIDDashed(a_Player.GetClientHandle()->GetUUID()));
Pkt.WriteString(a_Player.GetName());
const Json::Value & Properties = m_Client->GetProperties();
From afef7a79d7a214eec66e427da589172a40a18fef Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 13:53:23 +0200
Subject: [PATCH 029/751] Debuggers: Updated for the new cMojangAPI changes.
---
MCServer/Plugins/Debuggers/Debuggers.lua | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 80416acc7..575d696cb 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -287,7 +287,7 @@ function TestUUIDFromName()
"nonexistent_player",
}
-- WARNING: Blocking operation! DO NOT USE IN TICK THREAD!
- local UUIDs = cClientHandle:GetUUIDsFromPlayerNames(PlayerNames)
+ local UUIDs = cMojangAPI:GetUUIDsFromPlayerNames(PlayerNames)
-- Log the results:
for _, name in ipairs(PlayerNames) do
@@ -299,6 +299,15 @@ function TestUUIDFromName()
end
end
+ -- Test once more with the same players, valid-only. This should go directly from cache, so fast.
+ LOG("Testing again with the same valid players...")
+ local ValidPlayerNames =
+ {
+ "xoft",
+ "aloe_vera",
+ }
+ UUIDs = cMojangAPI:GetUUIDsFromPlayerNames(ValidPlayerNames);
+
LOG("UUID-from-Name resolution test finished.")
end
From 5daeba7e887ecf15b2facd3801f424a5bfcaa2e6 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 13:59:47 +0200
Subject: [PATCH 030/751] Removed lighting code in
cEnderman::CheckEventSeePlayer
---
src/Mobs/Enderman.cpp | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 6b7a22757..9c1cb7ce3 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -116,15 +116,7 @@ void cEnderman::CheckEventSeePlayer()
ASSERT(Callback.GetPlayer() != NULL);
- int CX, CZ;
- cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, CX, CZ);
- if (!GetWorld()->IsChunkLighted(CX, CZ))
- {
- GetWorld()->QueueLightChunk(CX, CZ);
- return;
- }
-
- if ((GetWorld()->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) - GetWorld()->GetSkyDarkness() < 15) && !Callback.GetPlayer()->IsGameModeCreative())
+ if (!Callback.GetPlayer()->IsGameModeCreative())
{
super::EventSeePlayer(Callback.GetPlayer());
m_EMState = CHASING;
From 1793644feff66b076980c669ede94d7b03eceafe Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 14:02:36 +0200
Subject: [PATCH 031/751] APIDump: Fixed UUID-related documentation.
---
MCServer/Plugins/APIDump/APIDesc.lua | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index e5114784e..692ca80ac 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -523,12 +523,12 @@ end
Functions =
{
- GenerateOfflineUUID = { Params = "Username", Return = "string", Notes = "(STATIC) Generates an UUID based on the player name provided. This is used for the offline (non-auth) mode, when there's no UUID source. Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. Returns a 36-char UUID (with dashes)." },
+ GenerateOfflineUUID = { Params = "Username", Return = "string", Notes = "(STATIC) Generates an UUID based on the player name provided. This is used for the offline (non-auth) mode, when there's no UUID source. Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. Returns a 32-char UUID (no dashes)." },
GetLocale = { Params = "", Return = "Locale", Notes = "Returns the locale string that the client sends as part of the protocol handshake. Can be used to provide localized strings." },
GetPing = { Params = "", Return = "number", Notes = "Returns the ping time, in ms" },
GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client. Note that this may be nil, for example if the player object is not yet spawned." },
GetUniqueID = { Params = "", Return = "number", Notes = "Returns the UniqueID of the client used to identify the client in the server" },
- GetUUID = { Params = "", Return = "string", Notes = "Returns the authentication-based UUID of the client. This UUID should be used to identify the player when persisting any player-related data." },
+ GetUUID = { Params = "", Return = "string", Notes = "Returns the authentication-based UUID of the client. This UUID should be used to identify the player when persisting any player-related data. Returns a 32-char UUID (no dashes)" },
GetUsername = { Params = "", Return = "string", Notes = "Returns the username that the client has provided" },
GetViewDistance = { Params = "", Return = "number", Notes = "Returns the viewdistance (number of chunks loaded for the player in each direction)" },
HasPluginChannel = { Params = "ChannelName", Return = "bool", Notes = "Returns true if the client has registered to receive messages on the specified plugin channel." },
From 426773df17dbd7748b51021a27119240de5b1922 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 14:03:14 +0200
Subject: [PATCH 032/751] ManualBindings: Fixed alignment.
---
src/Bindings/ManualBindings.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 026a6bad5..b1d302560 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -3141,9 +3141,9 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cClientHandle");
- tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE);
- tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE);
- tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage);
+ tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE);
+ tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE);
+ tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cMojangAPI");
From 85d64d291a6d11df6689190268c1f4c6b1c02cdd Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 14:09:30 +0200
Subject: [PATCH 033/751] MojangAPI: Clarified the UUID conversion code.
---
src/Protocol/MojangAPI.cpp | 15 +++++++++++++--
src/Protocol/MojangAPI.h | 6 ++++--
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 52afd71da..86ff134db 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -233,9 +233,14 @@ bool cMojangAPI::SecureRequest(const AString & a_ServerName, const AString & a_R
AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
{
+ // Note: we only check the string's length, not the actual content
switch (a_UUID.size())
{
- case 32: return a_UUID;
+ case 32:
+ {
+ // Already is a short UUID
+ return a_UUID;
+ }
case 36:
{
@@ -260,12 +265,18 @@ AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID)
{
+ // Note: we only check the string's length, not the actual content
switch (a_UUID.size())
{
- case 36: return a_UUID;
+ case 36:
+ {
+ // Already is a dashed UUID
+ return a_UUID;
+ }
case 32:
{
+ // Insert dashes at the proper positions:
AString res;
res.reserve(36);
res.append(a_UUID, 0, 8);
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index cc2902a19..c99f940ad 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -36,11 +36,13 @@ public:
// tolua_begin
/** Converts the given UUID to its short form (32 bytes, no dashes).
- Logs a warning and returns empty string if not a UUID. */
+ Logs a warning and returns empty string if not a UUID.
+ Note: only checks the string's length, not the actual content. */
static AString MakeUUIDShort(const AString & a_UUID);
/** Converts the given UUID to its dashed form (36 bytes, 4 dashes).
- Logs a warning and returns empty string if not a UUID. */
+ Logs a warning and returns empty string if not a UUID.
+ Note: only checks the string's length, not the actual content. */
static AString MakeUUIDDashed(const AString & a_UUID);
// tolua_end
From 5249f574bd077158836455fa66218e5fea6dcafe Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 15:55:50 +0200
Subject: [PATCH 034/751] Added RoofedForest trees. Could still be improved
allot.
---
src/Generating/Trees.cpp | 73 ++++++++++++++++++++++++++++++++++++++--
src/Generating/Trees.h | 2 ++
2 files changed, 73 insertions(+), 2 deletions(-)
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index c40322630..87405608b 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -218,7 +218,6 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No
return;
}
- case biRoofedForest:
case biColdTaiga:
case biColdTaigaHills:
case biMegaTaiga:
@@ -238,7 +237,6 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No
case biIcePlainsSpikes:
case biJungleM:
case biJungleEdgeM:
- case biRoofedForestM:
case biColdTaigaM:
case biMegaSpruceTaiga:
case biMegaSpruceTaigaHills:
@@ -253,6 +251,13 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No
GetBirchTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks);
return;
}
+
+ case biRoofedForest:
+ case biRoofedForestM:
+ {
+ GetRoofedForestTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks);
+ return;
+ }
case biDesert:
case biDesertHills:
@@ -807,3 +812,67 @@ void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
+
+void GetRoofedForestTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
+{
+ // Calculate a height
+ int Height = 5 + (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 11) % 4;
+
+ // Creat the trunk
+ for (int i = 0; i < Height; i++)
+ {
+ a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ a_LogBlocks.push_back(sSetBlock(a_BlockX + 1, a_BlockY + i, a_BlockZ, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ + 1, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ a_LogBlocks.push_back(sSetBlock(a_BlockX + 1, a_BlockY + i, a_BlockZ + 1, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ }
+
+ // Create branches
+ for (int i = 0; i < 3; i++)
+ {
+ //int x = (a_Noise.IntNoise3D(a_BlockX + 32 * a_Seq, a_BlockY * i, a_BlockZ + 32 * a_Seq) < 0 ? -1 : 2);
+ //int z = (a_Noise.IntNoise3D(a_BlockX - 32 * a_Seq, a_BlockY * i, a_BlockZ - 32 * a_Seq) < 0 ? -1 : 2);
+ int x = (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY * i, a_BlockZ + 32 * a_Seq) % 3) - 1;
+ int z = (a_Noise.IntNoise3DInt(a_BlockX - 32 * a_Seq, a_BlockY * i, a_BlockZ - 32 * a_Seq) % 3) - 1;
+
+ // The branches would end up in the trunk.
+ if ((x >= a_BlockX) && (x <= a_BlockX + 1) && (z >= a_BlockZ) && (z <= a_BlockZ + 1))
+ {
+ NOISE_DATATYPE Val1 = a_Noise.IntNoise2D(x, z);
+ if (Val1 < 0)
+ {
+ x = a_BlockX + (Val1 < -0.5) ? -1 : 3;
+ }
+ else
+ {
+ z = a_BlockZ + (Val1 < 0.5) ? -1 : 3;
+ }
+ }
+
+ int y = Height - (a_Noise.IntNoise3DInt(a_BlockX + x, a_BlockY * i, a_BlockZ - z) % (Height - (Height / 4)));
+
+ for (int Y = y; Y < Height; Y++)
+ {
+ a_LogBlocks.push_back(sSetBlock(a_BlockX + x, a_BlockY + Y, a_BlockZ + z, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ }
+ }
+
+ int hei = a_BlockY + Height - 2;
+
+ // The lower two leaves layers are BigO4 with log in the middle and possibly corners:
+ for (int i = 0; i < 2; i++)
+ {
+ PushCoordBlocks(a_BlockX, hei, a_BlockZ, a_OtherBlocks, BigO4, ARRAYCOUNT(BigO4), E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
+ PushCornerBlocks(a_BlockX, hei, a_BlockZ, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
+ hei++;
+ } // for i - 2*
+
+ // The top leaves layer is a BigO3 with leaves in the middle and possibly corners:
+ PushCoordBlocks(a_BlockX, hei, a_BlockZ, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
+ PushCornerBlocks(a_BlockX, hei, a_BlockZ, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
+ a_OtherBlocks.push_back(sSetBlock(a_BlockX, hei, a_BlockZ, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD));
+}
+
+
+
+
diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h
index 1f6ac4dff..2b2e0acc3 100644
--- a/src/Generating/Trees.h
+++ b/src/Generating/Trees.h
@@ -96,6 +96,8 @@ void GetLargeJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
/// Generates an image of a small jungle tree (1x1 trunk)
void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks);
+/// Generates an image of a roofed tree forest tree
+void GetRoofedForestTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks);
From a71c2da3f8ee329977902a36274d720908a77c48 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 17:07:57 +0200
Subject: [PATCH 035/751] APIDump: Added notes about cache to cMojangAPI.
---
MCServer/Plugins/APIDump/APIDesc.lua | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 692ca80ac..2a8ae90f9 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1619,7 +1619,13 @@ a_Player:OpenWindow(Window);
Mojang uses two formats for UUIDs, short and dashed. MCServer works with short UUIDs internally, but
will convert to dashed UUIDs where needed - in the protocol login for example. The MakeUUIDShort()
and MakeUUIDDashed() functions are provided for plugins to use for conversion between the two
- formats.
+ formats.
+
+ This class will cache values returned by the API service. The cache will hold the values for 7 days
+ by default, after that, they will no longer be available. This is in order to not let the server get
+ banned from using the API service, since they are rate-limited to 600 queries per 10 minutes. The
+ cache contents also gets updated whenever a player successfully joins, since that makes the server
+ contact the API service, too, and retrieve the relevant data.
]],
Functions =
{
From 17b679f355b8a63175815418983662c17ee13686 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 17:09:00 +0200
Subject: [PATCH 036/751] Fixed compiling using Clang
---
src/Generating/Trees.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index 87405608b..fb46a5e3b 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -830,8 +830,6 @@ void GetRoofedForestTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
// Create branches
for (int i = 0; i < 3; i++)
{
- //int x = (a_Noise.IntNoise3D(a_BlockX + 32 * a_Seq, a_BlockY * i, a_BlockZ + 32 * a_Seq) < 0 ? -1 : 2);
- //int z = (a_Noise.IntNoise3D(a_BlockX - 32 * a_Seq, a_BlockY * i, a_BlockZ - 32 * a_Seq) < 0 ? -1 : 2);
int x = (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY * i, a_BlockZ + 32 * a_Seq) % 3) - 1;
int z = (a_Noise.IntNoise3DInt(a_BlockX - 32 * a_Seq, a_BlockY * i, a_BlockZ - 32 * a_Seq) % 3) - 1;
@@ -841,11 +839,11 @@ void GetRoofedForestTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
NOISE_DATATYPE Val1 = a_Noise.IntNoise2D(x, z);
if (Val1 < 0)
{
- x = a_BlockX + (Val1 < -0.5) ? -1 : 3;
+ x = a_BlockX + ((Val1 < -0.5) ? -1 : 3);
}
else
{
- z = a_BlockZ + (Val1 < 0.5) ? -1 : 3;
+ z = a_BlockZ + ((Val1 < 0.5) ? -1 : 3);
}
}
From 0336e12cee0a784b076b5f9423bce2b9f803d1c8 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 30 Jul 2014 17:09:41 +0200
Subject: [PATCH 037/751] MojangAPI: Renamed cache file to MojangAPI.sqlite.
---
src/Protocol/MojangAPI.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 86ff134db..5fbc5b476 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -304,7 +304,7 @@ void cMojangAPI::LoadCachesFromDisk(void)
try
{
// Open up the SQLite DB:
- SQLite::Database db("NameToUUID.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+ SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)");
// Clean up old entries:
@@ -341,7 +341,7 @@ void cMojangAPI::SaveCachesToDisk(void)
try
{
// Open up the SQLite DB:
- SQLite::Database db("NameToUUID.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+ SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)");
// Remove all entries:
From c4e6a1423506c253974c7512a4b9b854a1e41b54 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 19:18:11 +0200
Subject: [PATCH 038/751] Added lighting code and added comments
---
src/Mobs/Enderman.cpp | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 9c1cb7ce3..f1f366d3b 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -116,6 +116,23 @@ void cEnderman::CheckEventSeePlayer()
ASSERT(Callback.GetPlayer() != NULL);
+ int ChunkX, ChunkZ;
+ cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ);
+
+ // Check if the chunk the enderman is in is lit.
+ if (!m_World->IsChunkLighted(ChunkX, ChunkZ))
+ {
+ m_World->QueueLightChunk(ChunkX, ChunkZ);
+ return;
+ }
+
+ // Enderman only attack if the skylight is higher than 6
+ if (m_World->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) <= 7)
+ {
+ // TODO: Teleport the enderman to a random spot.
+ return;
+ }
+
if (!Callback.GetPlayer()->IsGameModeCreative())
{
super::EventSeePlayer(Callback.GetPlayer());
From fd2d338a252a4c230e54e25a8695d7084a924bbe Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 21:42:48 +0200
Subject: [PATCH 039/751] Fixed comment at the end of a for-loop
---
src/Generating/Trees.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index fb46a5e3b..308947ad0 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -863,7 +863,7 @@ void GetRoofedForestTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
PushCoordBlocks(a_BlockX, hei, a_BlockZ, a_OtherBlocks, BigO4, ARRAYCOUNT(BigO4), E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
PushCornerBlocks(a_BlockX, hei, a_BlockZ, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
hei++;
- } // for i - 2*
+ } // for i < 2
// The top leaves layer is a BigO3 with leaves in the middle and possibly corners:
PushCoordBlocks(a_BlockX, hei, a_BlockZ, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
From f232ef5cd606d31068a758b3e784f33ca1860af0 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 21:50:02 +0200
Subject: [PATCH 040/751] Fixed doxy comment
---
src/Generating/Trees.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h
index 2b2e0acc3..2c54fce82 100644
--- a/src/Generating/Trees.h
+++ b/src/Generating/Trees.h
@@ -96,7 +96,7 @@ void GetLargeJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
/// Generates an image of a small jungle tree (1x1 trunk)
void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks);
-/// Generates an image of a roofed tree forest tree
+/// Generates an image of a roofed forest tree
void GetRoofedForestTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks);
From 6e0a8d393bafd0b018f168c4ef7a651a2955c1e8 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 21:56:33 +0200
Subject: [PATCH 041/751] Moved GetRoofedForestTreeImage content to
GetDarkoakTreeImage
---
src/Generating/Trees.cpp | 119 ++++++++++++++++++---------------------
src/Generating/Trees.h | 2 -
2 files changed, 55 insertions(+), 66 deletions(-)
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index 308947ad0..4786cad5a 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -255,7 +255,7 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No
case biRoofedForest:
case biRoofedForestM:
{
- GetRoofedForestTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks);
+ GetDarkoakTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks);
return;
}
@@ -412,7 +412,60 @@ void GetAcaciaTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noi
void GetDarkoakTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
{
- // TODO
+ // Calculate a height
+ int Height = 5 + (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 11) % 4;
+
+ // Creat the trunk
+ for (int i = 0; i < Height; i++)
+ {
+ a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ a_LogBlocks.push_back(sSetBlock(a_BlockX + 1, a_BlockY + i, a_BlockZ, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ + 1, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ a_LogBlocks.push_back(sSetBlock(a_BlockX + 1, a_BlockY + i, a_BlockZ + 1, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ }
+
+ // Create branches
+ for (int i = 0; i < 3; i++)
+ {
+ int x = (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY * i, a_BlockZ + 32 * a_Seq) % 3) - 1;
+ int z = (a_Noise.IntNoise3DInt(a_BlockX - 32 * a_Seq, a_BlockY * i, a_BlockZ - 32 * a_Seq) % 3) - 1;
+
+ // The branches would end up in the trunk.
+ if ((x >= a_BlockX) && (x <= a_BlockX + 1) && (z >= a_BlockZ) && (z <= a_BlockZ + 1))
+ {
+ NOISE_DATATYPE Val1 = a_Noise.IntNoise2D(x, z);
+ if (Val1 < 0)
+ {
+ x = a_BlockX + ((Val1 < -0.5) ? -1 : 3);
+ }
+ else
+ {
+ z = a_BlockZ + ((Val1 < 0.5) ? -1 : 3);
+ }
+ }
+
+ int y = Height - (a_Noise.IntNoise3DInt(a_BlockX + x, a_BlockY * i, a_BlockZ - z) % (Height - (Height / 4)));
+
+ for (int Y = y; Y < Height; Y++)
+ {
+ a_LogBlocks.push_back(sSetBlock(a_BlockX + x, a_BlockY + Y, a_BlockZ + z, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
+ }
+ }
+
+ int hei = a_BlockY + Height - 2;
+
+ // The lower two leaves layers are BigO4 with log in the middle and possibly corners:
+ for (int i = 0; i < 2; i++)
+ {
+ PushCoordBlocks(a_BlockX, hei, a_BlockZ, a_OtherBlocks, BigO4, ARRAYCOUNT(BigO4), E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
+ PushCornerBlocks(a_BlockX, hei, a_BlockZ, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
+ hei++;
+ } // for i < 2
+
+ // The top leaves layer is a BigO3 with leaves in the middle and possibly corners:
+ PushCoordBlocks(a_BlockX, hei, a_BlockZ, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
+ PushCornerBlocks(a_BlockX, hei, a_BlockZ, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
+ a_OtherBlocks.push_back(sSetBlock(a_BlockX, hei, a_BlockZ, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD));
}
@@ -812,65 +865,3 @@ void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
-
-void GetRoofedForestTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
-{
- // Calculate a height
- int Height = 5 + (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 11) % 4;
-
- // Creat the trunk
- for (int i = 0; i < Height; i++)
- {
- a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
- a_LogBlocks.push_back(sSetBlock(a_BlockX + 1, a_BlockY + i, a_BlockZ, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
- a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ + 1, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
- a_LogBlocks.push_back(sSetBlock(a_BlockX + 1, a_BlockY + i, a_BlockZ + 1, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
- }
-
- // Create branches
- for (int i = 0; i < 3; i++)
- {
- int x = (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY * i, a_BlockZ + 32 * a_Seq) % 3) - 1;
- int z = (a_Noise.IntNoise3DInt(a_BlockX - 32 * a_Seq, a_BlockY * i, a_BlockZ - 32 * a_Seq) % 3) - 1;
-
- // The branches would end up in the trunk.
- if ((x >= a_BlockX) && (x <= a_BlockX + 1) && (z >= a_BlockZ) && (z <= a_BlockZ + 1))
- {
- NOISE_DATATYPE Val1 = a_Noise.IntNoise2D(x, z);
- if (Val1 < 0)
- {
- x = a_BlockX + ((Val1 < -0.5) ? -1 : 3);
- }
- else
- {
- z = a_BlockZ + ((Val1 < 0.5) ? -1 : 3);
- }
- }
-
- int y = Height - (a_Noise.IntNoise3DInt(a_BlockX + x, a_BlockY * i, a_BlockZ - z) % (Height - (Height / 4)));
-
- for (int Y = y; Y < Height; Y++)
- {
- a_LogBlocks.push_back(sSetBlock(a_BlockX + x, a_BlockY + Y, a_BlockZ + z, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
- }
- }
-
- int hei = a_BlockY + Height - 2;
-
- // The lower two leaves layers are BigO4 with log in the middle and possibly corners:
- for (int i = 0; i < 2; i++)
- {
- PushCoordBlocks(a_BlockX, hei, a_BlockZ, a_OtherBlocks, BigO4, ARRAYCOUNT(BigO4), E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
- PushCornerBlocks(a_BlockX, hei, a_BlockZ, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
- hei++;
- } // for i < 2
-
- // The top leaves layer is a BigO3 with leaves in the middle and possibly corners:
- PushCoordBlocks(a_BlockX, hei, a_BlockZ, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
- PushCornerBlocks(a_BlockX, hei, a_BlockZ, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD);
- a_OtherBlocks.push_back(sSetBlock(a_BlockX, hei, a_BlockZ, E_BLOCK_NEW_LEAVES, E_META_NEW_LEAVES_DARK_OAK_WOOD));
-}
-
-
-
-
diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h
index 2c54fce82..1f6ac4dff 100644
--- a/src/Generating/Trees.h
+++ b/src/Generating/Trees.h
@@ -96,8 +96,6 @@ void GetLargeJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
/// Generates an image of a small jungle tree (1x1 trunk)
void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks);
-/// Generates an image of a roofed forest tree
-void GetRoofedForestTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks);
From 89b1bbdc5fca5a51df1a5dd18ce91f27cb667c04 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 30 Jul 2014 21:59:35 +0200
Subject: [PATCH 042/751] Added beacon.
---
src/BlockEntities/BeaconEntity.cpp | 333 +++++++++++++++++++++++---
src/BlockEntities/BeaconEntity.h | 58 ++++-
src/BlockEntities/FlowerPotEntity.cpp | 2 +-
src/Blocks/BlockHandler.cpp | 1 +
src/Blocks/BlockPiston.h | 1 +
src/ChunkMap.cpp | 1 +
src/ClientHandle.cpp | 54 +++++
src/ClientHandle.h | 5 +-
src/Protocol/Protocol17x.cpp | 15 ++
src/UI/SlotArea.cpp | 195 +++++++++++++++
src/UI/SlotArea.h | 29 +++
src/UI/Window.cpp | 31 +++
src/UI/Window.h | 21 ++
13 files changed, 701 insertions(+), 45 deletions(-)
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index 4b9662797..af6c124c0 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -3,33 +3,31 @@
#include "BeaconEntity.h"
#include "../BlockArea.h"
+#include "../Entities/Player.h"
-cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
- super(E_BLOCK_BEACON, a_BlockX, a_BlockY, a_BlockZ, a_World)
+cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World)
+ : super(E_BLOCK_BEACON, a_BlockX, a_BlockY, a_BlockZ, 1, 1, a_World)
+ , m_IsActive(false)
+ , m_BeaconLevel(0)
+ , m_PrimaryPotion(cEntityEffect::effNoEffect)
+ , m_SecondaryPotion(cEntityEffect::effNoEffect)
{
+ UpdateBeacon();
}
-int cBeaconEntity::GetPyramidLevel(void)
+char cBeaconEntity::CalculatePyramidLevel(void)
{
cBlockArea Area;
- int MinY = GetPosY() - 4;
- if (MinY < 0)
- {
- MinY = 0;
- }
- int MaxY = GetPosY() - 1;
- if (MaxY < 0)
- {
- MaxY = 0;
- }
+ int MinY = std::max(GetPosY() - 4, 0);
+ int MaxY = std::max(GetPosY() - 1, 0);
Area.Read(
m_World,
@@ -42,7 +40,7 @@ int cBeaconEntity::GetPyramidLevel(void)
int Layer = 1;
int MiddleXZ = 4;
- for (int Y = Area.GetSizeY() - 1; Y > 0; Y--)
+ for (int Y = (Area.GetSizeY() - 1); Y >= 0; Y--)
{
for (int X = MiddleXZ - Layer; X <= (MiddleXZ + Layer); X++)
{
@@ -50,14 +48,122 @@ int cBeaconEntity::GetPyramidLevel(void)
{
if (!IsMineralBlock(Area.GetRelBlockType(X, Y, Z)))
{
- return Layer - 1;
+ return (Layer - 1);
}
}
}
Layer++;
}
- return Layer - 1;
+ return (Layer - 1);
+}
+
+
+
+
+
+bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel)
+{
+ if (a_Potion == cEntityEffect::effNoEffect)
+ {
+ return true;
+ }
+
+ switch (a_BeaconLevel)
+ {
+ case 4:
+ {
+ // Beacon level 4
+ if (a_Potion == cEntityEffect::effRegeneration)
+ {
+ return true;
+ }
+ }
+ case 3:
+ {
+ // Beacon level 3
+ if (a_Potion == cEntityEffect::effStrength)
+ {
+ return true;
+ }
+ }
+ case 2:
+ {
+ // Beacon level 2
+ switch (a_Potion)
+ {
+ case cEntityEffect::effResistance:
+ case cEntityEffect::effJumpBoost:
+ {
+ return true;
+ }
+ }
+ }
+ case 1:
+ {
+ // Beacon level 1
+ switch (a_Potion)
+ {
+ case cEntityEffect::effSpeed:
+ case cEntityEffect::effHaste:
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+
+
+
+
+bool cBeaconEntity::SelectPrimaryPotion(cEntityEffect::eType a_Potion)
+{
+ LOG("SelectPrimaryPotion!");
+ if (!IsValidPotion(a_Potion, m_BeaconLevel))
+ {
+ LOG("FALLSE!");
+ return false;
+ }
+
+ m_PrimaryPotion = a_Potion;
+ return true;
+}
+
+
+
+
+
+bool cBeaconEntity::SelectSecondaryPotion(cEntityEffect::eType a_Potion)
+{
+ if (!IsValidPotion(a_Potion, m_BeaconLevel))
+ {
+ return false;
+ }
+
+ m_SecondaryPotion = a_Potion;
+ return true;
+}
+
+
+
+
+
+bool cBeaconEntity::IsBeaconBlocked(void)
+{
+ bool IsBlocked = false;
+ for (int Y = m_PosY; Y < cChunkDef::Height; ++Y)
+ {
+ BLOCKTYPE Block = m_World->GetBlock(m_PosX, Y, m_PosZ);
+ if (!cBlockInfo::IsTransparent(Block))
+ {
+ IsBlocked = true;
+ break;
+ }
+ }
+ return IsBlocked;
}
@@ -83,8 +189,102 @@ bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType)
+void cBeaconEntity::UpdateBeacon(void)
+{
+ if (IsBeaconBlocked())
+ {
+ m_IsActive = false;
+ m_BeaconLevel = 0;
+ }
+ else
+ {
+ m_BeaconLevel = CalculatePyramidLevel();
+ m_IsActive = (m_BeaconLevel > 0);
+ }
+
+ // TODO: Add achievement
+}
+
+
+
+
+
+void cBeaconEntity::GiveEffects(void)
+{
+ if (!m_IsActive || (m_BeaconLevel < 0))
+ {
+ return;
+ }
+
+ int Radius = m_BeaconLevel * 10 + 10;
+ short EffectLevel = 0;
+ if ((m_BeaconLevel >= 4) && (m_PrimaryPotion == m_SecondaryPotion))
+ {
+ EffectLevel = 1;
+ }
+
+ cEntityEffect::eType SecondaryPotion = cEntityEffect::effNoEffect;
+ if ((m_BeaconLevel >= 4) && (m_PrimaryPotion != m_SecondaryPotion) && (m_SecondaryPotion > 0))
+ {
+ SecondaryPotion = m_SecondaryPotion;
+ }
+
+ class cPlayerCallback : public cPlayerListCallback
+ {
+ int m_Radius;
+ int m_PosX, m_PosY, m_PosZ;
+ cEntityEffect::eType m_PrimaryPotion, m_SecondaryPotion;
+ short m_EffectLevel;
+
+ virtual bool Item(cPlayer * a_Player)
+ {
+ Vector3d PlayerPosition = Vector3d(a_Player->GetPosition());
+ if (PlayerPosition.y > (double)m_PosY)
+ {
+ PlayerPosition.y = (double)m_PosY;
+ }
+
+ // TODO: Vanilla minecraft uses an AABB check instead of a radius one
+ Vector3d BeaconPosition = Vector3d(m_PosX, m_PosY, m_PosZ);
+ if ((PlayerPosition - BeaconPosition).Length() <= m_Radius)
+ {
+ a_Player->AddEntityEffect(m_PrimaryPotion, 180, m_EffectLevel);
+
+ if (m_SecondaryPotion != cEntityEffect::effNoEffect)
+ {
+ a_Player->AddEntityEffect(m_SecondaryPotion, 180, 0);
+ }
+ }
+ return false;
+ }
+
+ public:
+ cPlayerCallback(int a_Radius, int a_PosX, int a_PosY, int a_PosZ, cEntityEffect::eType a_PrimaryPotion, cEntityEffect::eType a_SecondaryPotion, short a_EffectLevel)
+ : m_Radius(a_Radius)
+ , m_PosX(a_PosX)
+ , m_PosY(a_PosY)
+ , m_PosZ(a_PosZ)
+ , m_PrimaryPotion(a_PrimaryPotion)
+ , m_SecondaryPotion(a_SecondaryPotion)
+ , m_EffectLevel(a_EffectLevel)
+ {};
+
+ } PlayerCallback(Radius, m_PosX, m_PosY, m_PosZ, m_PrimaryPotion, SecondaryPotion, EffectLevel);
+ GetWorld()->ForEachPlayer(PlayerCallback);
+}
+
+
+
+
+
bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
+ // Update the beacon every 4 seconds
+ if ((GetWorld()->GetWorldAge() % 80) == 0)
+ {
+ UpdateBeacon();
+ GiveEffects();
+ }
return false;
}
@@ -92,23 +292,94 @@ bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk)
-void cBeaconEntity::SaveToJson(Json::Value& a_Value)
-{
-}
-
-
-
-
-void cBeaconEntity::SendTo(cClientHandle & a_Client)
-{
-}
-
-
-
-
-
void cBeaconEntity::UsedBy(cPlayer * a_Player)
{
+ cWindow * Window = GetWindow();
+ if (Window == NULL)
+ {
+ OpenWindow(new cBeaconWindow(m_PosX, m_PosY, m_PosZ, this));
+ Window = GetWindow();
+ }
+
+ if (Window != NULL)
+ {
+ // if (a_Player->GetWindow() != Window)
+ // -> Because mojang doesn't send a 'close window' packet when you click the cancel button in the beacon inventory ...
+ {
+ a_Player->OpenWindow(Window);
+ }
+ }
+}
+
+
+
+
+
+bool cBeaconEntity::LoadFromJson(const Json::Value & a_Value)
+{
+ m_PosX = a_Value.get("x", 0).asInt();
+ m_PosY = a_Value.get("y", 0).asInt();
+ m_PosZ = a_Value.get("z", 0).asInt();
+
+ Json::Value AllSlots = a_Value.get("Slots", 0);
+ int SlotIdx = 0;
+ for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr)
+ {
+ cItem Item;
+ Item.FromJson(*itr);
+ SetSlot(SlotIdx, Item);
+ SlotIdx++;
+ }
+
+ m_BeaconLevel = (char)a_Value.get("Level", 0).asInt();
+ int PrimaryPotion = a_Value.get("PrimaryPotion", 0).asInt();
+ int SecondaryPotion = a_Value.get("SecondaryPotion", 0).asInt();
+
+ if ((PrimaryPotion >= 0) && (PrimaryPotion <= (int)cEntityEffect::effSaturation))
+ {
+ m_PrimaryPotion = (cEntityEffect::eType)PrimaryPotion;
+ }
+
+ if ((SecondaryPotion >= 0) && (SecondaryPotion <= (int)cEntityEffect::effSaturation))
+ {
+ m_SecondaryPotion = (cEntityEffect::eType)SecondaryPotion;
+ }
+
+ return true;
+}
+
+
+
+
+
+void cBeaconEntity::SaveToJson(Json::Value& a_Value)
+{
+ a_Value["x"] = m_PosX;
+ a_Value["y"] = m_PosY;
+ a_Value["z"] = m_PosZ;
+
+ Json::Value AllSlots;
+ int NumSlots = m_Contents.GetNumSlots();
+ for (int i = 0; i < NumSlots; i++)
+ {
+ Json::Value Slot;
+ m_Contents.GetSlot(i).GetJson(Slot);
+ AllSlots.append(Slot);
+ }
+ a_Value["Slots"] = AllSlots;
+
+ a_Value["Level"] = m_BeaconLevel;
+ a_Value["PrimaryPotion"] = (int)m_PrimaryPotion;
+ a_Value["SecondaryPotion"] = (int)m_SecondaryPotion;
+}
+
+
+
+
+
+void cBeaconEntity::SendTo(cClientHandle & a_Client)
+{
+ a_Client.SendUpdateBlockEntity(*this);
}
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index ee1eda391..52111e82a 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -1,7 +1,7 @@
#pragma once
-#include "BlockEntity.h"
+#include "BlockEntityWithItems.h"
@@ -17,26 +17,60 @@ namespace Json
class cBeaconEntity :
- public cBlockEntity
+ public cBlockEntityWithItems
{
- typedef cBlockEntity super;
+ typedef cBlockEntityWithItems super;
public:
-
- /** The initial constructor */
cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
-
- /** Returns the amount of layers the pyramid below the beacon has. */
- int GetPyramidLevel(void);
+
+ /** Is the beacon active? */
+ bool IsActive(void) const { return m_IsActive; }
+
+ /** Returns the beacon level. (0 - 4) */
+ char GetBeaconLevel(void) const { return m_BeaconLevel; }
+
+ char GetPrimaryPotion(void) const { return m_PrimaryPotion; }
+ char GetSecondaryPotion(void) const { return m_SecondaryPotion; }
+
+ /** Select the primary potion. Returns false when the potion is invalid.*/
+ bool SelectPrimaryPotion(cEntityEffect::eType a_Potion);
+
+ /** Select the secondary potion. Returns false when the potion is invalid. */
+ bool SelectSecondaryPotion(cEntityEffect::eType a_Potion);
+
+ /** Calculate the amount of layers the pyramid below the beacon has. */
+ char CalculatePyramidLevel(void);
+
+ /** Is the beacon blocked by non-transparent blocks that are higher than the beacon? */
+ bool IsBeaconBlocked(void);
/** Returns true if the block is a diamond block, a golden block, an iron block or an emerald block. */
static bool IsMineralBlock(BLOCKTYPE a_BlockType);
+
+ /** Returns true if the potion can be used. */
+ static bool IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel);
+
+ /** Update the beacon. */
+ void UpdateBeacon(void);
+
+ /** Give the near-players the effects. */
+ void GiveEffects(void);
+
+ bool LoadFromJson(const Json::Value & a_Value);
// cBlockEntity overrides:
- virtual void SaveToJson(Json::Value& a_Value) override;
- virtual void SendTo(cClientHandle & a_Client) override;
- virtual void UsedBy(cPlayer * a_Player) override;
- virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */) override;
+ virtual void SaveToJson(Json::Value& a_Value) override;
+ virtual void SendTo(cClientHandle & a_Client) override;
+ virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void UsedBy(cPlayer * a_Player) override;
+
+protected:
+ bool m_IsActive;
+ char m_BeaconLevel;
+
+ cEntityEffect::eType m_PrimaryPotion, m_SecondaryPotion;
+
} ;
diff --git a/src/BlockEntities/FlowerPotEntity.cpp b/src/BlockEntities/FlowerPotEntity.cpp
index 87bf8b921..e001634b8 100644
--- a/src/BlockEntities/FlowerPotEntity.cpp
+++ b/src/BlockEntities/FlowerPotEntity.cpp
@@ -1,7 +1,7 @@
// FlowerPotEntity.cpp
-// Implements the cFlowerPotEntity class representing a single sign in the world
+// Implements the cFlowerPotEntity class representing a single flower pot in the world
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "json/json.h"
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index ddb0186c9..52f7dd608 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -181,6 +181,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_ACACIA_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType);
case E_BLOCK_ACTIVATOR_RAIL: return new cBlockRailHandler (a_BlockType);
case E_BLOCK_ANVIL: return new cBlockAnvilHandler (a_BlockType);
+ case E_BLOCK_BEACON: return new cBlockEntityHandler (a_BlockType);
case E_BLOCK_BED: return new cBlockBedHandler (a_BlockType);
case E_BLOCK_BIG_FLOWER: return new cBlockBigFlowerHandler (a_BlockType);
case E_BLOCK_BIRCH_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType);
diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h
index bbb8af75b..0bec603e3 100644
--- a/src/Blocks/BlockPiston.h
+++ b/src/Blocks/BlockPiston.h
@@ -94,6 +94,7 @@ private:
switch (a_BlockType)
{
case E_BLOCK_ANVIL:
+ case E_BLOCK_BEACON:
case E_BLOCK_BEDROCK:
case E_BLOCK_BREWING_STAND:
case E_BLOCK_CHEST:
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 05d219918..38e0cd82d 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1839,6 +1839,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
}
case E_BLOCK_OBSIDIAN:
+ case E_BLOCK_BEACON:
case E_BLOCK_BEDROCK:
case E_BLOCK_WATER:
case E_BLOCK_LAVA:
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 30ec737be..849de2ce1 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -31,6 +31,7 @@
#include "Items/ItemSword.h"
#include "polarssl/md5.h"
+#include "BlockEntities/BeaconEntity.h"
@@ -659,6 +660,10 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString
// Client <-> Server branding exchange
SendPluginMessage("MC|Brand", "MCServer");
}
+ else if (a_Channel == "MC|Beacon")
+ {
+ HandleBeaconSelection(a_Message.c_str(), a_Message.size());
+ }
else if (a_Channel == "MC|ItemName")
{
HandleAnvilItemName(a_Message.c_str(), a_Message.size());
@@ -746,6 +751,55 @@ void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList
+void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length)
+{
+ if (a_Length < 14)
+ {
+ SendChat("Failure setting beacon selection; bad request", mtFailure);
+ LOGD("Malformed MC|Beacon packet.");
+ return;
+ }
+
+ cWindow * Window = m_Player->GetWindow();
+ if ((Window == NULL) || (Window->GetWindowType() != cWindow::wtBeacon))
+ {
+ return;
+ }
+ cBeaconWindow * BeaconWindow = (cBeaconWindow *) Window;
+
+ if (Window->GetSlot(*m_Player, 0)->IsEmpty())
+ {
+ return;
+ }
+
+ cByteBuffer Buffer(a_Length);
+ Buffer.Write(a_Data, a_Length);
+
+ int PrimaryPotionID, SecondaryPotionID;
+ Buffer.ReadBEInt(PrimaryPotionID);
+ Buffer.ReadBEInt(SecondaryPotionID);
+
+ cEntityEffect::eType PrimaryPotion = cEntityEffect::effNoEffect;
+ if ((PrimaryPotionID >= 0) && (PrimaryPotionID <= (int)cEntityEffect::effSaturation))
+ {
+ PrimaryPotion = (cEntityEffect::eType)PrimaryPotionID;
+ }
+
+ cEntityEffect::eType SecondaryPotion = cEntityEffect::effNoEffect;
+ if ((SecondaryPotionID >= 0) && (SecondaryPotionID <= (int)cEntityEffect::effSaturation))
+ {
+ SecondaryPotion = (cEntityEffect::eType)SecondaryPotionID;
+ }
+
+ Window->SetSlot(*m_Player, 0, cItem());
+ BeaconWindow->GetBeaconEntity()->SelectPrimaryPotion(PrimaryPotion);
+ BeaconWindow->GetBeaconEntity()->SelectSecondaryPotion(SecondaryPotion);
+}
+
+
+
+
+
void cClientHandle::HandleCommandBlockMessage(const char * a_Data, size_t a_Length)
{
if (a_Length < 14)
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 48eba4de1..f3f1da417 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -399,7 +399,10 @@ private:
/** Removes all of the channels from the list of current plugin channels. Ignores channels that are not found. */
void UnregisterPluginChannels(const AStringVector & a_ChannelList);
-
+
+ /** Handles the "MC|Beacon" plugin message */
+ void HandleBeaconSelection(const char * a_Data, size_t a_Length);
+
/** Handles the "MC|AdvCdm" plugin message */
void HandleCommandBlockMessage(const char * a_Data, size_t a_Length);
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 45d39e0e9..8a68edd1f 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -37,6 +37,7 @@ Implements the 1.7.x protocol classes:
#include "../Mobs/IncludeAllMonsters.h"
#include "../UI/Window.h"
+#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
#include "../BlockEntities/FlowerPotEntity.h"
@@ -1328,6 +1329,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
{
case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing
case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text
+ case E_BLOCK_BEACON: Action = 3; break; // Update beacon entity
case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity
case E_BLOCK_FLOWER_POT: Action = 5; break; // Update flower pot
default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break;
@@ -2581,6 +2583,19 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
switch (a_BlockEntity.GetBlockType())
{
+ case E_BLOCK_BEACON:
+ {
+ cBeaconEntity & BeaconEntity = (cBeaconEntity &)a_BlockEntity;
+
+ Writer.AddInt("x", BeaconEntity.GetPosX());
+ Writer.AddInt("y", BeaconEntity.GetPosY());
+ Writer.AddInt("z", BeaconEntity.GetPosZ());
+ Writer.AddInt("Primary", BeaconEntity.GetPrimaryPotion());
+ Writer.AddInt("Secondary", BeaconEntity.GetSecondaryPotion());
+ Writer.AddInt("Levels", BeaconEntity.GetBeaconLevel());
+ Writer.AddString("id", "Beacon"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
+ break;
+ }
case E_BLOCK_COMMAND_BLOCK:
{
cCommandBlockEntity & CommandBlockEntity = (cCommandBlockEntity &)a_BlockEntity;
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index b5f84c24c..4199bbf56 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -5,6 +5,7 @@
#include "Globals.h"
#include "SlotArea.h"
#include "../Entities/Player.h"
+#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/DropSpenserEntity.h"
#include "../BlockEntities/EnderChestEntity.h"
@@ -1190,6 +1191,200 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
+////////////////////////////////////////////////////////////////////////////////
+// cSlotAreaBeacon:
+
+cSlotAreaBeacon::cSlotAreaBeacon(cBeaconEntity * a_Beacon, cWindow & a_ParentWindow) :
+ cSlotArea(1, a_ParentWindow),
+ m_Beacon(a_Beacon)
+{
+ m_Beacon->GetContents().AddListener(*this);
+}
+
+
+
+
+
+cSlotAreaBeacon::~cSlotAreaBeacon()
+{
+ m_Beacon->GetContents().RemoveListener(*this);
+}
+
+
+
+
+bool cSlotAreaBeacon::IsPlaceableItem(short a_ItemType)
+{
+ switch (a_ItemType)
+ {
+ case E_ITEM_EMERALD:
+ case E_ITEM_DIAMOND:
+ case E_ITEM_GOLD:
+ case E_ITEM_IRON:
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
+void cSlotAreaBeacon::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
+{
+ ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots()));
+
+ bool bAsync = false;
+ if (GetSlot(a_SlotNum, a_Player) == NULL)
+ {
+ LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum);
+ return;
+ }
+
+ switch (a_ClickAction)
+ {
+ case caShiftLeftClick:
+ case caShiftRightClick:
+ {
+ ShiftClicked(a_Player, a_SlotNum, a_ClickedItem);
+ return;
+ }
+ case caMiddleClick:
+ {
+ MiddleClicked(a_Player, a_SlotNum);
+ return;
+ }
+ case caDropKey:
+ case caCtrlDropKey:
+ {
+ DropClicked(a_Player, a_SlotNum, false);
+ return;
+ }
+ case caNumber1:
+ case caNumber2:
+ case caNumber3:
+ case caNumber4:
+ case caNumber5:
+ case caNumber6:
+ case caNumber7:
+ case caNumber8:
+ case caNumber9:
+ {
+ NumberClicked(a_Player, a_SlotNum, a_ClickAction);
+ return;
+ }
+ default:
+ {
+ break;
+ }
+ }
+
+ cItem Slot(*GetSlot(a_SlotNum, a_Player));
+ if (!Slot.IsSameType(a_ClickedItem))
+ {
+ LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots);
+ LOGWARNING("My item: %s", ItemToFullString(Slot).c_str());
+ LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str());
+ bAsync = true;
+ }
+ cItem & DraggingItem = a_Player.GetDraggingItem();
+
+ if (DraggingItem.IsEmpty())
+ {
+ DraggingItem = Slot;
+ Slot.Empty();
+ }
+ else if (Slot.IsEmpty())
+ {
+ if (!IsPlaceableItem(DraggingItem.m_ItemType))
+ {
+ return;
+ }
+
+ Slot = DraggingItem.CopyOne();
+ DraggingItem.m_ItemCount -= 1;
+ if (DraggingItem.m_ItemCount <= 0)
+ {
+ DraggingItem.Empty();
+ }
+ }
+ else if (DraggingItem.m_ItemCount == 1)
+ {
+ if (!IsPlaceableItem(DraggingItem.m_ItemCount))
+ {
+ return;
+ }
+
+ // Switch contents
+ cItem tmp(DraggingItem);
+ DraggingItem = Slot;
+ Slot = tmp;
+ }
+
+ SetSlot(a_SlotNum, a_Player, Slot);
+ if (bAsync)
+ {
+ m_ParentWindow.BroadcastWholeWindow();
+ }
+}
+
+
+
+
+
+void cSlotAreaBeacon::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots)
+{
+ const cItem * Slot = GetSlot(0, a_Player);
+ if (!Slot->IsEmpty() || !IsPlaceableItem(a_ItemStack.m_ItemType) || (a_ItemStack.m_ItemCount != 1))
+ {
+ return;
+ }
+
+ if (a_ShouldApply)
+ {
+ SetSlot(0, a_Player, a_ItemStack.CopyOne());
+ }
+ a_ItemStack.Empty();
+}
+
+
+
+
+
+const cItem * cSlotAreaBeacon::GetSlot(int a_SlotNum, cPlayer & a_Player) const
+{
+ UNUSED(a_Player);
+ return &(m_Beacon->GetSlot(a_SlotNum));
+}
+
+
+
+
+
+void cSlotAreaBeacon::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item)
+{
+ UNUSED(a_Player);
+ m_Beacon->SetSlot(a_SlotNum, a_Item);
+}
+
+
+
+
+
+void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
+{
+ UNUSED(a_SlotNum);
+ // Something has changed in the window, broadcast the entire window to all clients
+ ASSERT(a_ItemGrid == &(m_Beacon->GetContents()));
+
+ m_ParentWindow.BroadcastWholeWindow();
+}
+
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cSlotAreaEnchanting:
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index fa842bb81..9a96f2f3c 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -15,6 +15,7 @@
class cWindow;
class cPlayer;
+class cBeaconEntity;
class cChestEntity;
class cDropSpenserEntity;
class cEnderChestEntity;
@@ -314,6 +315,34 @@ protected:
+class cSlotAreaBeacon :
+ public cSlotArea,
+ public cItemGrid::cListener
+{
+ typedef cSlotArea super;
+
+public:
+ cSlotAreaBeacon(cBeaconEntity * a_Beacon, cWindow & a_ParentWindow);
+ virtual ~cSlotAreaBeacon();
+
+ bool IsPlaceableItem(short a_ItemType);
+
+ virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
+ virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override;
+ virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
+ virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
+
+protected:
+ cBeaconEntity * m_Beacon;
+
+ // cItemGrid::cListener overrides:
+ virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
+} ;
+
+
+
+
+
class cSlotAreaEnchanting :
public cSlotAreaTemporary
{
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index 4731f282b..aa129bfe8 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -9,6 +9,7 @@
#include "../Entities/Pickup.h"
#include "../Inventory.h"
#include "../Items/ItemHandler.h"
+#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/DropSpenserEntity.h"
#include "../BlockEntities/EnderChestEntity.h"
@@ -840,6 +841,36 @@ void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
+////////////////////////////////////////////////////////////////////////////////
+// cBeaconWindow:
+
+cBeaconWindow::cBeaconWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconEntity * a_Beacon) :
+ cWindow(wtBeacon, "Beacon"),
+ m_Beacon(a_Beacon)
+{
+ m_ShouldDistributeToHotbarFirst = true;
+ m_SlotAreas.push_back(new cSlotAreaBeacon(m_Beacon, *this));
+ m_SlotAreas.push_back(new cSlotAreaInventory(*this));
+ m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
+}
+
+
+
+
+
+void cBeaconWindow::OpenedByPlayer(cPlayer & a_Player)
+{
+ super::OpenedByPlayer(a_Player);
+
+ a_Player.GetClientHandle()->SendWindowProperty(*this, 0, m_Beacon->GetBeaconLevel());
+ a_Player.GetClientHandle()->SendWindowProperty(*this, 1, m_Beacon->GetPrimaryPotion());
+ a_Player.GetClientHandle()->SendWindowProperty(*this, 2, m_Beacon->GetSecondaryPotion());
+}
+
+
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cEnchantingWindow:
diff --git a/src/UI/Window.h b/src/UI/Window.h
index 97db0ca88..9fb0e3b38 100644
--- a/src/UI/Window.h
+++ b/src/UI/Window.h
@@ -23,6 +23,7 @@ class cDropSpenserEntity;
class cEnderChestEntity;
class cFurnaceEntity;
class cHopperEntity;
+class cBeaconEntity;
class cSlotArea;
class cSlotAreaAnvil;
class cWorld;
@@ -258,6 +259,26 @@ protected:
+class cBeaconWindow :
+ public cWindow
+{
+ typedef cWindow super;
+public:
+ cBeaconWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconEntity * a_Beacon);
+
+ cBeaconEntity * GetBeaconEntity(void) const { return m_Beacon; }
+
+ // cWindow Overrides:
+ virtual void OpenedByPlayer(cPlayer & a_Player) override;
+
+protected:
+ cBeaconEntity * m_Beacon;
+} ;
+
+
+
+
+
class cEnchantingWindow :
public cWindow
{
From 81e095adda62e4067ab4c07b0e4c7ce0f3dbce39 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 30 Jul 2014 22:19:51 +0200
Subject: [PATCH 043/751] Exported the beacon.
---
src/Bindings/AllToLua.pkg | 1 +
src/Bindings/CMakeLists.txt | 1 +
src/Bindings/ManualBindings.cpp | 2 ++
src/BlockEntities/BeaconEntity.cpp | 2 --
src/BlockEntities/BeaconEntity.h | 42 +++++++++++++++++++-----------
src/Chunk.cpp | 33 +++++++++++++++++++++++
src/Chunk.h | 5 ++++
src/ChunkMap.cpp | 18 +++++++++++++
src/ChunkMap.h | 5 ++++
src/World.cpp | 10 +++++++
src/World.h | 5 ++++
11 files changed, 107 insertions(+), 17 deletions(-)
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 1e5dfd2fe..621358662 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -47,6 +47,7 @@ $cfile "../Inventory.h"
$cfile "../Enchantments.h"
$cfile "../Item.h"
$cfile "../ItemGrid.h"
+$cfile "../BlockEntities/BeaconEntity.h"
$cfile "../BlockEntities/BlockEntity.h"
$cfile "../BlockEntities/BlockEntityWithItems.h"
$cfile "../BlockEntities/ChestEntity.h"
diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt
index 48e7ce79c..a2b381a26 100644
--- a/src/Bindings/CMakeLists.txt
+++ b/src/Bindings/CMakeLists.txt
@@ -53,6 +53,7 @@ set(BINDING_DEPENDENCIES
../Bindings/WebPlugin.h
../BiomeDef.h
../BlockArea.h
+ ../BlockEntities/BeaconEntity.h
../BlockEntities/BlockEntity.h
../BlockEntities/BlockEntityWithItems.h
../BlockEntities/ChestEntity.h
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index df9687fc0..460d879d5 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -16,6 +16,7 @@
#include "../WebAdmin.h"
#include "../ClientHandle.h"
#include "../BlockArea.h"
+#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/DispenserEntity.h"
@@ -2996,6 +2997,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cWorld");
tolua_function(tolua_S, "ChunkStay", tolua_cWorld_ChunkStay);
tolua_function(tolua_S, "DoWithBlockEntityAt", tolua_DoWithXYZ);
+ tolua_function(tolua_S, "DoWithBeaconAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithChestAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithDispenserAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithDropSpenserAt", tolua_DoWithXYZ);
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index af6c124c0..38b710181 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -121,10 +121,8 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
bool cBeaconEntity::SelectPrimaryPotion(cEntityEffect::eType a_Potion)
{
- LOG("SelectPrimaryPotion!");
if (!IsValidPotion(a_Potion, m_BeaconLevel))
{
- LOG("FALLSE!");
return false;
}
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index 52111e82a..4710e91e0 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -1,3 +1,10 @@
+// BeaconEntity.h
+
+// Declares the cBeaconEntity class representing a single beacon in the world
+
+
+
+
#pragma once
@@ -16,14 +23,26 @@ namespace Json
+// tolua_begin
class cBeaconEntity :
public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
public:
+ // tolua_end
+
cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
+ bool LoadFromJson(const Json::Value & a_Value);
+ // cBlockEntity overrides:
+ virtual void SaveToJson(Json::Value& a_Value) override;
+ virtual void SendTo(cClientHandle & a_Client) override;
+ virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void UsedBy(cPlayer * a_Player) override;
+
+ // tolua_begin
+
/** Is the beacon active? */
bool IsActive(void) const { return m_IsActive; }
@@ -45,33 +64,26 @@ public:
/** Is the beacon blocked by non-transparent blocks that are higher than the beacon? */
bool IsBeaconBlocked(void);
- /** Returns true if the block is a diamond block, a golden block, an iron block or an emerald block. */
- static bool IsMineralBlock(BLOCKTYPE a_BlockType);
-
- /** Returns true if the potion can be used. */
- static bool IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel);
-
/** Update the beacon. */
void UpdateBeacon(void);
/** Give the near-players the effects. */
void GiveEffects(void);
- bool LoadFromJson(const Json::Value & a_Value);
-
- // cBlockEntity overrides:
- virtual void SaveToJson(Json::Value& a_Value) override;
- virtual void SendTo(cClientHandle & a_Client) override;
- virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
- virtual void UsedBy(cPlayer * a_Player) override;
+ /** Returns true if the block is a diamond block, a golden block, an iron block or an emerald block. */
+ static bool IsMineralBlock(BLOCKTYPE a_BlockType);
+
+ /** Returns true if the potion can be used. */
+ static bool IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel);
+
+ // tolua_end
protected:
bool m_IsActive;
char m_BeaconLevel;
cEntityEffect::eType m_PrimaryPotion, m_SecondaryPotion;
-
-} ;
+} ; // tolua_export
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index b83036b6d..cd7dc698c 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -11,6 +11,7 @@
#include "Server.h"
#include "zlib/zlib.h"
#include "Defines.h"
+#include "BlockEntities/BeaconEntity.h"
#include "BlockEntities/ChestEntity.h"
#include "BlockEntities/DispenserEntity.h"
#include "BlockEntities/DropperEntity.h"
@@ -2126,6 +2127,38 @@ bool cChunk::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBloc
+bool cChunk::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback)
+{
+ // The blockentity list is locked by the parent chunkmap's CS
+ for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2)
+ {
+ ++itr2;
+ if (((*itr)->GetPosX() != a_BlockX) || ((*itr)->GetPosY() != a_BlockY) || ((*itr)->GetPosZ() != a_BlockZ))
+ {
+ continue;
+ }
+ if ((*itr)->GetBlockType() != E_BLOCK_BEACON)
+ {
+ // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out
+ return false;
+ }
+
+ // The correct block entity is here
+ if (a_Callback.Item((cBeaconEntity *)*itr))
+ {
+ return false;
+ }
+ return true;
+ } // for itr - m_BlockEntitites[]
+
+ // Not found:
+ return false;
+}
+
+
+
+
+
bool cChunk::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback)
{
// The blockentity list is locked by the parent chunkmap's CS
diff --git a/src/Chunk.h b/src/Chunk.h
index 7eee3999c..5cde3f08f 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -28,6 +28,7 @@ class cServer;
class MTRand;
class cPlayer;
class cChunkMap;
+class cBeaconEntity;
class cChestEntity;
class cDispenserEntity;
class cFurnaceEntity;
@@ -45,6 +46,7 @@ class cMobSpawner;
typedef std::list cClientHandleList;
typedef cItemCallback cEntityCallback;
+typedef cItemCallback cBeaconCallback;
typedef cItemCallback cChestCallback;
typedef cItemCallback cDispenserCallback;
typedef cItemCallback cFurnaceCallback;
@@ -236,6 +238,9 @@ public:
/** 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 */
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
+ /** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
+ bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
+
/** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */
bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Lua-acessible
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 38e0cd82d..dd8be0631 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -2116,6 +2116,24 @@ bool cChunkMap::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cB
+bool cChunkMap::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback)
+{
+ int ChunkX, ChunkZ;
+ int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
+ cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ if ((Chunk == NULL) || !Chunk->IsValid())
+ {
+ return false;
+ }
+ return Chunk->DoWithBeaconAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
+}
+
+
+
+
+
bool cChunkMap::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback)
{
int ChunkX, ChunkZ;
diff --git a/src/ChunkMap.h b/src/ChunkMap.h
index e33d9f894..1e9a0f982 100644
--- a/src/ChunkMap.h
+++ b/src/ChunkMap.h
@@ -19,6 +19,7 @@ class MTRand;
class cChunkStay;
class cChunk;
class cPlayer;
+class cBeaconEntity;
class cChestEntity;
class cDispenserEntity;
class cDropperEntity;
@@ -40,6 +41,7 @@ typedef std::list cClientHandleList;
typedef cChunk * cChunkPtr;
typedef cItemCallback cEntityCallback;
typedef cItemCallback cBlockEntityCallback;
+typedef cItemCallback cBeaconCallback;
typedef cItemCallback cChestCallback;
typedef cItemCallback cDispenserCallback;
typedef cItemCallback cDropperCallback;
@@ -234,6 +236,9 @@ public:
/** 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 */
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
+ /** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
+ bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
+
/** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */
bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Lua-acessible
diff --git a/src/World.cpp b/src/World.cpp
index 348498693..b3c4b1de0 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -25,6 +25,7 @@
#include "Entities/TNTEntity.h"
#include "BlockEntities/CommandBlockEntity.h"
+#include "BlockEntities/BeaconEntity.h"
// Simulators:
#include "Simulator/SimulatorManager.h"
@@ -1232,6 +1233,15 @@ bool cWorld::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBloc
+bool cWorld::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback& a_Callback)
+{
+ return m_ChunkMap->DoWithBeaconAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
+}
+
+
+
+
+
bool cWorld::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback)
{
return m_ChunkMap->DoWithChestAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
diff --git a/src/World.h b/src/World.h
index 4d0ccf2dd..90b798e8e 100644
--- a/src/World.h
+++ b/src/World.h
@@ -41,6 +41,7 @@ class cEntity;
class cBlockEntity;
class cWorldGenerator; // The generator that actually generates the chunks for a single world
class cChunkGenerator; // The thread responsible for generating chunks
+class cBeaconEntity;
class cChestEntity;
class cDispenserEntity;
class cFlowerPotEntity;
@@ -59,6 +60,7 @@ typedef std::vector cSetChunkDataPtrs;
typedef cItemCallback cPlayerListCallback;
typedef cItemCallback cEntityCallback;
+typedef cItemCallback cBeaconCallback;
typedef cItemCallback cChestCallback;
typedef cItemCallback cDispenserCallback;
typedef cItemCallback cFurnaceCallback;
@@ -523,6 +525,9 @@ public:
/** 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
+ /** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
+ bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Exported in ManualBindings.cpp
+
/** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */
bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Exported in ManualBindings.cpp
From ad4fa6eba823de90f528e199c9f7e61bdb3f55f3 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 30 Jul 2014 22:22:06 +0200
Subject: [PATCH 044/751] Changed return type from GetPrimaryPotion() and
GetSecondaryPotion()
---
src/BlockEntities/BeaconEntity.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index 4710e91e0..07b2b85dc 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -49,8 +49,8 @@ public:
/** Returns the beacon level. (0 - 4) */
char GetBeaconLevel(void) const { return m_BeaconLevel; }
- char GetPrimaryPotion(void) const { return m_PrimaryPotion; }
- char GetSecondaryPotion(void) const { return m_SecondaryPotion; }
+ cEntityEffect::eType GetPrimaryPotion(void) const { return m_PrimaryPotion; }
+ cEntityEffect::eType GetSecondaryPotion(void) const { return m_SecondaryPotion; }
/** Select the primary potion. Returns false when the potion is invalid.*/
bool SelectPrimaryPotion(cEntityEffect::eType a_Potion);
From 66d34b83d27a72ed4cc2598527c25dfb8c1a873c Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 30 Jul 2014 22:31:43 +0200
Subject: [PATCH 045/751] Added beacon documentation.
---
MCServer/Plugins/APIDump/APIDesc.lua | 1 +
.../Plugins/APIDump/Classes/BlockEntities.lua | 26 +++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index e65da1d16..2a592e1e1 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2244,6 +2244,7 @@ end
DigBlock = { Params = "X, Y, Z", Return = "", Notes = "Replaces the specified block with air, without dropping the usual pickups for the block. Wakes up the simulators for the block and its neighbors." },
DoExplosionAt = { Params = "Force, X, Y, Z, CanCauseFire, Source, SourceData", Return = "", Notes = "Creates an explosion of the specified relative force in the specified position. If CanCauseFire is set, the explosion will set blocks on fire, too. The Source parameter specifies the source of the explosion, one of the esXXX constants. The SourceData parameter is specific to each source type, usually it provides more info about the source." },
DoWithBlockEntityAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a block entity at the specified coords, calls the CallbackFunction with the {{cBlockEntity}} parameter representing the block entity. The CallbackFunction has the following signature: function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])
The function returns false if there is no block entity, or if there is, it returns the bool value that the callback has returned. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." },
+ DoWithBeaconAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a beacon at the specified coords, calls the CallbackFunction with the {{cBeaconEntity}} parameter representing the beacon. The CallbackFunction has the following signature: function Callback({{cBeaconEntity|BeaconEntity}}, [CallbackData])
The function returns false if there is no beacon, or if there is, it returns the bool value that the callback has returned." },
DoWithChestAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a chest at the specified coords, calls the CallbackFunction with the {{cChestEntity}} parameter representing the chest. The CallbackFunction has the following signature: function Callback({{cChestEntity|ChestEntity}}, [CallbackData])
The function returns false if there is no chest, or if there is, it returns the bool value that the callback has returned." },
DoWithCommandBlockAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a command block at the specified coords, calls the CallbackFunction with the {{cCommandBlockEntity}} parameter representing the command block. The CallbackFunction has the following signature: function Callback({{cCommandBlockEntity|CommandBlockEntity}}, [CallbackData])
The function returns false if there is no command block, or if there is, it returns the bool value that the callback has returned." },
DoWithDispenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dispenser at the specified coords, calls the CallbackFunction with the {{cDispenserEntity}} parameter representing the dispenser. The CallbackFunction has the following signature: function Callback({{cDispenserEntity|DispenserEntity}}, [CallbackData])
The function returns false if there is no dispenser, or if there is, it returns the bool value that the callback has returned." },
diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
index de42f66df..294d47295 100644
--- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
+++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
@@ -50,6 +50,32 @@ return
},
},
+ cBeaconEntity =
+ {
+ Desc = [[
+ A beacon entity is a {{cBlockEntityWithItems|cBlockEntityWithItems}} descendant that represents a beacon
+ in the world.
+ ]],
+
+ Inherits = "cBlockEntityWithItems",
+
+ Functions =
+ {
+ IsActive = { Params = "", Return = "bool", Notes = "Is the beacon active?" },
+ GetBeaconLevel = { Params = "", Return = "number", Notes = "Returns the beacon level. (0 - 4)" },
+ GetPrimaryPotion = { Params = "", Return = "EffectType", Notes = "Returns the primary potion." },
+ GetSecondaryPotion = { Params = "", Return = "EffectType", Notes = "Returns the secondary potion." },
+ SelectPrimaryPotion = { Params = "EffectType", Return = "bool", Notes = "Select the primary potion. Returns false when the potion is invalid." },
+ SelectSecondaryPotion = { Params = "EffectType", Return = "bool", Notes = "Select the secondary potion. Returns false when the potion is invalid." },
+ CalculatePyramidLevel = { Params = "", Return = "number", Notes = "Calculate the amount of layers the pyramid below the beacon has." },
+ IsBeaconBlocked = { Params = "", Return = "bool", Notes = "Is the beacon blocked by non-transparent blocks that are higher than the beacon?" },
+ UpdateBeacon = { Params = "", Return = "", Notes = "Update the beacon." },
+ GiveEffects = { Params = "", Return = "", Notes = "Give the near-players the effects." },
+ IsMineralBlock = { Params = "BLOCKTYPE", Return = "bool", Notes = "Returns true if the block is a diamond block, a golden block, an iron block or an emerald block." },
+ IsValidPotion = { Params = "EffectType", Return = "bool", Notes = "Returns true if the potion can be used." },
+ },
+ },
+
cChestEntity =
{
Desc = [[
From 7821326370385ddcfe2ac28034727d02abf104da Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 30 Jul 2014 22:43:59 +0200
Subject: [PATCH 046/751] Suggestions
---
src/Generating/Trees.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index 4786cad5a..32594d0b4 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -412,10 +412,10 @@ void GetAcaciaTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noi
void GetDarkoakTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
{
- // Calculate a height
+ // Pick a height
int Height = 5 + (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 11) % 4;
- // Creat the trunk
+ // Create the trunk
for (int i = 0; i < Height; i++)
{
a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ, E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD));
From dcd226d9040409dec41c8f1f8909262946308ab0 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 30 Jul 2014 22:50:34 +0200
Subject: [PATCH 047/751] Added beacon load/save.
---
src/BlockEntities/BeaconEntity.h | 3 ++
src/WorldStorage/NBTChunkSerializer.cpp | 19 ++++++++++
src/WorldStorage/NBTChunkSerializer.h | 2 +
src/WorldStorage/WSSAnvil.cpp | 50 ++++++++++++++++++++++++-
src/WorldStorage/WSSAnvil.h | 1 +
5 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index 07b2b85dc..59a4bdbd9 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -41,6 +41,9 @@ public:
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void UsedBy(cPlayer * a_Player) override;
+ /** Modify the beacon level. (It is needed to load the beacon corectly) */
+ void SetBeaconLevel(char a_Level) { m_BeaconLevel = a_Level; }
+
// tolua_begin
/** Is the beacon active? */
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 4857da1b6..63387c33d 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -10,6 +10,7 @@
#include "../StringCompression.h"
#include "FastNBT.h"
+#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/DispenserEntity.h"
@@ -176,6 +177,23 @@ void cNBTChunkSerializer::AddBasicTileEntity(cBlockEntity * a_Entity, const char
+void cNBTChunkSerializer::AddBeaconEntity(cBeaconEntity * a_Entity)
+{
+ m_Writer.BeginCompound("");
+ AddBasicTileEntity(a_Entity, "Beacon");
+ m_Writer.AddInt("Levels", a_Entity->GetBeaconLevel());
+ m_Writer.AddInt("Primary", (int)a_Entity->GetPrimaryPotion());
+ m_Writer.AddInt("Secondary", (int)a_Entity->GetSecondaryPotion());
+ m_Writer.BeginList("Items", TAG_Compound);
+ AddItemGrid(a_Entity->GetContents());
+ m_Writer.EndList();
+ m_Writer.EndCompound();
+}
+
+
+
+
+
void cNBTChunkSerializer::AddChestEntity(cChestEntity * a_Entity, BLOCKTYPE a_ChestType)
{
m_Writer.BeginCompound("");
@@ -825,6 +843,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity)
// Add tile-entity into NBT:
switch (a_Entity->GetBlockType())
{
+ case E_BLOCK_BEACON: AddBeaconEntity ((cBeaconEntity *) a_Entity); break;
case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity, a_Entity->GetBlockType()); break;
case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *)a_Entity); break;
case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break;
diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h
index 710a06a70..4c229a65c 100644
--- a/src/WorldStorage/NBTChunkSerializer.h
+++ b/src/WorldStorage/NBTChunkSerializer.h
@@ -20,6 +20,7 @@ class cFastNBTWriter;
class cEntity;
class cBlockEntity;
class cBoat;
+class cBeaconEntity;
class cChestEntity;
class cCommandBlockEntity;
class cDispenserEntity;
@@ -93,6 +94,7 @@ protected:
// Block entities:
void AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID);
+ void AddBeaconEntity (cBeaconEntity * a_Entity);
void AddChestEntity (cChestEntity * a_Entity, BLOCKTYPE a_ChestType);
void AddDispenserEntity(cDispenserEntity * a_Entity);
void AddDropperEntity (cDropperEntity * a_Entity);
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 71ff3ef99..5a1972fd4 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -16,6 +16,7 @@
#include "../StringCompression.h"
#include "../SetChunkData.h"
+#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/DispenserEntity.h"
@@ -582,7 +583,11 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
{
continue;
}
- if (strncmp(a_NBT.GetData(sID), "Chest", a_NBT.GetDataLength(sID)) == 0)
+ if (strncmp(a_NBT.GetData(sID), "Beacon", a_NBT.GetDataLength(sID)) == 0)
+ {
+ LoadBeaconFromNBT(a_BlockEntities, a_NBT, Child);
+ }
+ else if (strncmp(a_NBT.GetData(sID), "Chest", a_NBT.GetDataLength(sID)) == 0)
{
LoadChestFromNBT(a_BlockEntities, a_NBT, Child, E_BLOCK_CHEST);
}
@@ -746,6 +751,49 @@ void cWSSAnvil::LoadItemGridFromNBT(cItemGrid & a_ItemGrid, const cParsedNBT & a
+void cWSSAnvil::LoadBeaconFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
+ int x, y, z;
+ if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z))
+ {
+ return;
+ }
+
+ std::auto_ptr Beacon(new cBeaconEntity(x, y, z, m_World));
+
+ int CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Levels");
+ if (CurrentLine >= 0)
+ {
+ Beacon->SetBeaconLevel((char)a_NBT.GetInt(CurrentLine));
+ }
+
+ CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Primary");
+ if (CurrentLine >= 0)
+ {
+ Beacon->SelectPrimaryPotion((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
+ }
+
+ CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Secondary");
+ if (CurrentLine >= 0)
+ {
+ Beacon->SelectSecondaryPotion((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
+ }
+
+ // We are better than mojang, we load/save the beacon inventory!
+ int Items = a_NBT.FindChildByName(a_TagIdx, "Items");
+ if ((Items >= 0) && (a_NBT.GetType(Items) == TAG_List))
+ {
+ LoadItemGridFromNBT(Beacon->GetContents(), a_NBT, Items);
+ }
+
+ a_BlockEntities.push_back(Beacon.release());
+}
+
+
+
+
+
void cWSSAnvil::LoadChestFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE a_ChestType)
{
ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index 9f8714404..f8eeb8247 100644
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -133,6 +133,7 @@ protected:
*/
void LoadItemGridFromNBT(cItemGrid & a_ItemGrid, const cParsedNBT & a_NBT, int a_ItemsTagIdx, int s_SlotOffset = 0);
+ void LoadBeaconFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadChestFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE a_ChestType);
void LoadDispenserFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadDropperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
From e6ca5a5ece61d8a4dd69b877a91f567edf2a3f63 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 30 Jul 2014 22:54:19 +0200
Subject: [PATCH 048/751] Added window update.
---
src/BlockEntities/BeaconEntity.cpp | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index 38b710181..30d927663 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -127,6 +127,12 @@ bool cBeaconEntity::SelectPrimaryPotion(cEntityEffect::eType a_Potion)
}
m_PrimaryPotion = a_Potion;
+
+ // Send window update:
+ if (GetWindow() != NULL)
+ {
+ GetWindow()->SetProperty(1, m_PrimaryPotion);
+ }
return true;
}
@@ -142,6 +148,12 @@ bool cBeaconEntity::SelectSecondaryPotion(cEntityEffect::eType a_Potion)
}
m_SecondaryPotion = a_Potion;
+
+ // Send window update:
+ if (GetWindow() != NULL)
+ {
+ GetWindow()->SetProperty(2, m_SecondaryPotion);
+ }
return true;
}
@@ -189,6 +201,8 @@ bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType)
void cBeaconEntity::UpdateBeacon(void)
{
+ int OldBeaconLevel = m_BeaconLevel;
+
if (IsBeaconBlocked())
{
m_IsActive = false;
@@ -200,6 +214,15 @@ void cBeaconEntity::UpdateBeacon(void)
m_IsActive = (m_BeaconLevel > 0);
}
+ if (m_BeaconLevel != OldBeaconLevel)
+ {
+ // Send window update:
+ if (GetWindow() != NULL)
+ {
+ GetWindow()->SetProperty(0, m_BeaconLevel);
+ }
+ }
+
// TODO: Add achievement
}
From 8b519bf6e20a987c9544ef11f0df6467831cc069 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Thu, 31 Jul 2014 10:02:50 +0200
Subject: [PATCH 049/751] MojangAPI: Added a UseCachedOnly param to
GetUUIDsFromPlayerNames().
---
MCServer/Plugins/APIDump/APIDesc.lua | 2 +-
MCServer/Plugins/Debuggers/Debuggers.lua | 32 +++++++++++++++++++++++-
src/Bindings/ManualBindings.cpp | 19 ++++++++++----
src/Protocol/MojangAPI.cpp | 7 ++++--
src/Protocol/MojangAPI.h | 6 +++--
5 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 2a8ae90f9..9d0e90999 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1630,7 +1630,7 @@ a_Player:OpenWindow(Window);
Functions =
{
AddPlayerNameToUUIDMapping = { Params = "PlayerName, UUID", Return = "", Notes = "Adds the specified PlayerName-to-UUID mapping into the cache, with current timestamp." },
- GetUUIDsFromPlayerNames = { Params = "PlayerNames", Return = "table", Notes = "Returns a table that contains the map, 'PlayerName' -> 'UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. Queries the Mojang servers for the results. WARNING: Do NOT use this function while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
+ GetUUIDsFromPlayerNames = { Params = "PlayerNames, [UseOnlyCached]", Return = "table", Notes = "Returns a table that contains the map, 'PlayerName' -> 'UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. If UseOnlyCached is false (the default), queries the Mojang servers for the results that are not in the cache.
WARNING: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
MakeUUIDDashed = { Params = "UUID", Return = "DashedUUID", Notes = "(STATIC) Converts the UUID to a dashed format (\"01234567-8901-2345-6789-012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
MakeUUIDShort = { Params = "UUID", Return = "ShortUUID", Notes = "(STATIC) Converts the UUID to a short format (without dashes, \"01234567890123456789012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
},
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 575d696cb..075cfa40c 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -307,8 +307,38 @@ function TestUUIDFromName()
"aloe_vera",
}
UUIDs = cMojangAPI:GetUUIDsFromPlayerNames(ValidPlayerNames);
+
+ -- Log the results:
+ for _, name in ipairs(ValidPlayerNames) do
+ local UUID = UUIDs[name]
+ if (UUID == nil) then
+ LOG(" UUID(" .. name .. ") not found.")
+ else
+ LOG(" UUID(" .. name .. ") = \"" .. UUID .. "\"")
+ end
+ end
+
+ -- Test yet again, cache-only:
+ LOG("Testing once more, cache only...")
+ local PlayerNames3 =
+ {
+ "xoft",
+ "aloe_vera",
+ "notch", -- Valid player name, but not cached (most likely :)
+ }
+ UUIDs = cMojangAPI:GetUUIDsFromPlayerNames(PlayerNames3, true)
- LOG("UUID-from-Name resolution test finished.")
+ -- Log the results:
+ for _, name in ipairs(PlayerNames3) do
+ local UUID = UUIDs[name]
+ if (UUID == nil) then
+ LOG(" UUID(" .. name .. ") not found.")
+ else
+ LOG(" UUID(" .. name .. ") = \"" .. UUID .. "\"")
+ end
+ end
+
+ LOG("UUID-from-Name resolution tests finished.")
end
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index b1d302560..038173c99 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2163,7 +2163,7 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
if (
!S.CheckParamUserTable(1, "cMojangAPI") ||
!S.CheckParamTable(2) ||
- !S.CheckParamEnd(3)
+ !S.CheckParamEnd(4)
)
{
return 0;
@@ -2177,19 +2177,27 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
{
lua_rawgeti(L, 2, i);
AString Name;
- S.GetStackValue(3, Name);
+ S.GetStackValue(-1, Name);
if (!Name.empty())
{
PlayerNames.push_back(Name);
}
lua_pop(L, 1);
}
+
+ // If the UseOnlyCached param was given, read it; default to false
+ bool ShouldUseCacheOnly = false;
+ if (lua_gettop(L) == 3)
+ {
+ ShouldUseCacheOnly = (lua_toboolean(L, 3) != 0);
+ lua_pop(L, 1);
+ }
// Push the output table onto the stack:
- lua_newtable(L); // stack index 3
+ lua_newtable(L);
// Get the UUIDs:
- AStringVector UUIDs = cRoot::Get()->GetMojangAPI().GetUUIDsFromPlayerNames(PlayerNames);
+ AStringVector UUIDs = cRoot::Get()->GetMojangAPI().GetUUIDsFromPlayerNames(PlayerNames, ShouldUseCacheOnly);
if (UUIDs.size() != PlayerNames.size())
{
// A hard error has occured while processing the request, no UUIDs were returned. Return an empty table:
@@ -2197,7 +2205,8 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
}
// Convert to output table, PlayerName -> UUID:
- for (int i = 0; i < NumNames; i++)
+ size_t len = UUIDs.size();
+ for (size_t i = 0; i < len; i++)
{
if (UUIDs[i].empty())
{
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 5fbc5b476..71a5e53de 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -129,7 +129,7 @@ void cMojangAPI::Start(cIniFile & a_SettingsIni)
-AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames)
+AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames, bool a_UseOnlyCached)
{
// Convert all playernames to lowercase:
AStringVector PlayerNames;
@@ -140,7 +140,10 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player
} // for itr - a_PlayerNames[]
// Request the cache to populate any names not yet contained:
- CacheNamesToUUIDs(PlayerNames);
+ if (!a_UseOnlyCached)
+ {
+ CacheNamesToUUIDs(PlayerNames);
+ }
// Retrieve from cache:
size_t idx = 0;
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index c99f940ad..ac8995bb5 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -50,8 +50,10 @@ public:
/** Converts the player names into UUIDs.
a_PlayerName[idx] will be converted to UUID and returned as idx-th value
The UUID will be empty on error.
- Blocking operation, do not use in world-tick thread! */
- AStringVector GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName);
+ If a_UseOnlyCached is true, only the cached values are returned.
+ If a_UseOnlyCached is false, the names not found in the cache are looked up online, which is a blocking
+ operation, do not use this in world-tick thread! */
+ AStringVector GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName, bool a_UseOnlyCached = false);
// tolua_begin
From 556fc908aedcc36388e9d859487b140045e5e33e Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 12:13:11 +0200
Subject: [PATCH 050/751] Renamed functions and added beacon json saving.
---
src/BlockEntities/BeaconEntity.cpp | 78 ++++++++++++-------------
src/BlockEntities/BeaconEntity.h | 12 ++--
src/ClientHandle.cpp | 24 ++++----
src/Protocol/Protocol17x.cpp | 4 +-
src/UI/Window.cpp | 4 +-
src/WorldStorage/NBTChunkSerializer.cpp | 4 +-
src/WorldStorage/WSSAnvil.cpp | 4 +-
src/WorldStorage/WSSCompact.cpp | 20 +++++++
8 files changed, 84 insertions(+), 66 deletions(-)
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index 30d927663..c94783ba8 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -13,8 +13,8 @@ cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld *
: super(E_BLOCK_BEACON, a_BlockX, a_BlockY, a_BlockZ, 1, 1, a_World)
, m_IsActive(false)
, m_BeaconLevel(0)
- , m_PrimaryPotion(cEntityEffect::effNoEffect)
- , m_SecondaryPotion(cEntityEffect::effNoEffect)
+ , m_PrimaryEffect(cEntityEffect::effNoEffect)
+ , m_SecondaryEffect(cEntityEffect::effNoEffect)
{
UpdateBeacon();
}
@@ -62,9 +62,9 @@ char cBeaconEntity::CalculatePyramidLevel(void)
-bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel)
+bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel)
{
- if (a_Potion == cEntityEffect::effNoEffect)
+ if (a_Effect == cEntityEffect::effNoEffect)
{
return true;
}
@@ -74,7 +74,7 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
case 4:
{
// Beacon level 4
- if (a_Potion == cEntityEffect::effRegeneration)
+ if (a_Effect == cEntityEffect::effRegeneration)
{
return true;
}
@@ -82,7 +82,7 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
case 3:
{
// Beacon level 3
- if (a_Potion == cEntityEffect::effStrength)
+ if (a_Effect == cEntityEffect::effStrength)
{
return true;
}
@@ -90,7 +90,7 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
case 2:
{
// Beacon level 2
- switch (a_Potion)
+ switch (a_Effect)
{
case cEntityEffect::effResistance:
case cEntityEffect::effJumpBoost:
@@ -102,7 +102,7 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
case 1:
{
// Beacon level 1
- switch (a_Potion)
+ switch (a_Effect)
{
case cEntityEffect::effSpeed:
case cEntityEffect::effHaste:
@@ -119,19 +119,19 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
-bool cBeaconEntity::SelectPrimaryPotion(cEntityEffect::eType a_Potion)
+bool cBeaconEntity::SelectPrimaryEffect(cEntityEffect::eType a_Effect)
{
- if (!IsValidPotion(a_Potion, m_BeaconLevel))
+ if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
return false;
}
- m_PrimaryPotion = a_Potion;
+ m_PrimaryEffect = a_Effect;
// Send window update:
if (GetWindow() != NULL)
{
- GetWindow()->SetProperty(1, m_PrimaryPotion);
+ GetWindow()->SetProperty(1, m_PrimaryEffect);
}
return true;
}
@@ -140,19 +140,19 @@ bool cBeaconEntity::SelectPrimaryPotion(cEntityEffect::eType a_Potion)
-bool cBeaconEntity::SelectSecondaryPotion(cEntityEffect::eType a_Potion)
+bool cBeaconEntity::SelectSecondaryEffect(cEntityEffect::eType a_Effect)
{
- if (!IsValidPotion(a_Potion, m_BeaconLevel))
+ if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
return false;
}
- m_SecondaryPotion = a_Potion;
+ m_SecondaryEffect = a_Effect;
// Send window update:
if (GetWindow() != NULL)
{
- GetWindow()->SetProperty(2, m_SecondaryPotion);
+ GetWindow()->SetProperty(2, m_SecondaryEffect);
}
return true;
}
@@ -163,17 +163,15 @@ bool cBeaconEntity::SelectSecondaryPotion(cEntityEffect::eType a_Potion)
bool cBeaconEntity::IsBeaconBlocked(void)
{
- bool IsBlocked = false;
for (int Y = m_PosY; Y < cChunkDef::Height; ++Y)
{
BLOCKTYPE Block = m_World->GetBlock(m_PosX, Y, m_PosZ);
if (!cBlockInfo::IsTransparent(Block))
{
- IsBlocked = true;
- break;
+ return true;
}
}
- return IsBlocked;
+ return false;
}
@@ -239,22 +237,22 @@ void cBeaconEntity::GiveEffects(void)
int Radius = m_BeaconLevel * 10 + 10;
short EffectLevel = 0;
- if ((m_BeaconLevel >= 4) && (m_PrimaryPotion == m_SecondaryPotion))
+ if ((m_BeaconLevel >= 4) && (m_PrimaryEffect == m_SecondaryEffect))
{
EffectLevel = 1;
}
- cEntityEffect::eType SecondaryPotion = cEntityEffect::effNoEffect;
- if ((m_BeaconLevel >= 4) && (m_PrimaryPotion != m_SecondaryPotion) && (m_SecondaryPotion > 0))
+ cEntityEffect::eType SecondaryEffect = cEntityEffect::effNoEffect;
+ if ((m_BeaconLevel >= 4) && (m_PrimaryEffect != m_SecondaryEffect) && (m_SecondaryEffect > 0))
{
- SecondaryPotion = m_SecondaryPotion;
+ SecondaryEffect = m_SecondaryEffect;
}
class cPlayerCallback : public cPlayerListCallback
{
int m_Radius;
int m_PosX, m_PosY, m_PosZ;
- cEntityEffect::eType m_PrimaryPotion, m_SecondaryPotion;
+ cEntityEffect::eType m_PrimaryEffect, m_SecondaryEffect;
short m_EffectLevel;
virtual bool Item(cPlayer * a_Player)
@@ -269,28 +267,28 @@ void cBeaconEntity::GiveEffects(void)
Vector3d BeaconPosition = Vector3d(m_PosX, m_PosY, m_PosZ);
if ((PlayerPosition - BeaconPosition).Length() <= m_Radius)
{
- a_Player->AddEntityEffect(m_PrimaryPotion, 180, m_EffectLevel);
+ a_Player->AddEntityEffect(m_PrimaryEffect, 180, m_EffectLevel);
- if (m_SecondaryPotion != cEntityEffect::effNoEffect)
+ if (m_SecondaryEffect != cEntityEffect::effNoEffect)
{
- a_Player->AddEntityEffect(m_SecondaryPotion, 180, 0);
+ a_Player->AddEntityEffect(m_SecondaryEffect, 180, 0);
}
}
return false;
}
public:
- cPlayerCallback(int a_Radius, int a_PosX, int a_PosY, int a_PosZ, cEntityEffect::eType a_PrimaryPotion, cEntityEffect::eType a_SecondaryPotion, short a_EffectLevel)
+ cPlayerCallback(int a_Radius, int a_PosX, int a_PosY, int a_PosZ, cEntityEffect::eType a_PrimaryEffect, cEntityEffect::eType a_SecondaryEffect, short a_EffectLevel)
: m_Radius(a_Radius)
, m_PosX(a_PosX)
, m_PosY(a_PosY)
, m_PosZ(a_PosZ)
- , m_PrimaryPotion(a_PrimaryPotion)
- , m_SecondaryPotion(a_SecondaryPotion)
+ , m_PrimaryEffect(a_PrimaryEffect)
+ , m_SecondaryEffect(a_SecondaryEffect)
, m_EffectLevel(a_EffectLevel)
{};
- } PlayerCallback(Radius, m_PosX, m_PosY, m_PosZ, m_PrimaryPotion, SecondaryPotion, EffectLevel);
+ } PlayerCallback(Radius, m_PosX, m_PosY, m_PosZ, m_PrimaryEffect, SecondaryEffect, EffectLevel);
GetWorld()->ForEachPlayer(PlayerCallback);
}
@@ -353,17 +351,17 @@ bool cBeaconEntity::LoadFromJson(const Json::Value & a_Value)
}
m_BeaconLevel = (char)a_Value.get("Level", 0).asInt();
- int PrimaryPotion = a_Value.get("PrimaryPotion", 0).asInt();
- int SecondaryPotion = a_Value.get("SecondaryPotion", 0).asInt();
+ int PrimaryEffect = a_Value.get("PrimaryEffect", 0).asInt();
+ int SecondaryEffect = a_Value.get("SecondaryEffect", 0).asInt();
- if ((PrimaryPotion >= 0) && (PrimaryPotion <= (int)cEntityEffect::effSaturation))
+ if ((PrimaryEffect >= 0) && (PrimaryEffect <= (int)cEntityEffect::effSaturation))
{
- m_PrimaryPotion = (cEntityEffect::eType)PrimaryPotion;
+ m_PrimaryEffect = (cEntityEffect::eType)PrimaryEffect;
}
- if ((SecondaryPotion >= 0) && (SecondaryPotion <= (int)cEntityEffect::effSaturation))
+ if ((SecondaryEffect >= 0) && (SecondaryEffect <= (int)cEntityEffect::effSaturation))
{
- m_SecondaryPotion = (cEntityEffect::eType)SecondaryPotion;
+ m_SecondaryEffect = (cEntityEffect::eType)SecondaryEffect;
}
return true;
@@ -390,8 +388,8 @@ void cBeaconEntity::SaveToJson(Json::Value& a_Value)
a_Value["Slots"] = AllSlots;
a_Value["Level"] = m_BeaconLevel;
- a_Value["PrimaryPotion"] = (int)m_PrimaryPotion;
- a_Value["SecondaryPotion"] = (int)m_SecondaryPotion;
+ a_Value["PrimaryEffect"] = (int)m_PrimaryEffect;
+ a_Value["SecondaryEffect"] = (int)m_SecondaryEffect;
}
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index 59a4bdbd9..5cf8da24e 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -52,14 +52,14 @@ public:
/** Returns the beacon level. (0 - 4) */
char GetBeaconLevel(void) const { return m_BeaconLevel; }
- cEntityEffect::eType GetPrimaryPotion(void) const { return m_PrimaryPotion; }
- cEntityEffect::eType GetSecondaryPotion(void) const { return m_SecondaryPotion; }
+ cEntityEffect::eType GetPrimaryEffect(void) const { return m_PrimaryEffect; }
+ cEntityEffect::eType GetSecondaryEffect(void) const { return m_SecondaryEffect; }
/** Select the primary potion. Returns false when the potion is invalid.*/
- bool SelectPrimaryPotion(cEntityEffect::eType a_Potion);
+ bool SelectPrimaryEffect(cEntityEffect::eType a_Effect);
/** Select the secondary potion. Returns false when the potion is invalid. */
- bool SelectSecondaryPotion(cEntityEffect::eType a_Potion);
+ bool SelectSecondaryEffect(cEntityEffect::eType a_Effect);
/** Calculate the amount of layers the pyramid below the beacon has. */
char CalculatePyramidLevel(void);
@@ -77,7 +77,7 @@ public:
static bool IsMineralBlock(BLOCKTYPE a_BlockType);
/** Returns true if the potion can be used. */
- static bool IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel);
+ static bool IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel);
// tolua_end
@@ -85,7 +85,7 @@ protected:
bool m_IsActive;
char m_BeaconLevel;
- cEntityEffect::eType m_PrimaryPotion, m_SecondaryPotion;
+ cEntityEffect::eType m_PrimaryEffect, m_SecondaryEffect;
} ; // tolua_export
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 849de2ce1..e833f338a 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -7,6 +7,7 @@
#include "Bindings/PluginManager.h"
#include "Entities/Player.h"
#include "Inventory.h"
+#include "BlockEntities/BeaconEntity.h"
#include "BlockEntities/ChestEntity.h"
#include "BlockEntities/CommandBlockEntity.h"
#include "BlockEntities/SignEntity.h"
@@ -31,7 +32,6 @@
#include "Items/ItemSword.h"
#include "polarssl/md5.h"
-#include "BlockEntities/BeaconEntity.h"
@@ -775,25 +775,25 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length)
cByteBuffer Buffer(a_Length);
Buffer.Write(a_Data, a_Length);
- int PrimaryPotionID, SecondaryPotionID;
- Buffer.ReadBEInt(PrimaryPotionID);
- Buffer.ReadBEInt(SecondaryPotionID);
+ int PrimaryEffectID, SecondaryEffectID;
+ Buffer.ReadBEInt(PrimaryEffectID);
+ Buffer.ReadBEInt(SecondaryEffectID);
- cEntityEffect::eType PrimaryPotion = cEntityEffect::effNoEffect;
- if ((PrimaryPotionID >= 0) && (PrimaryPotionID <= (int)cEntityEffect::effSaturation))
+ cEntityEffect::eType PrimaryEffect = cEntityEffect::effNoEffect;
+ if ((PrimaryEffectID >= 0) && (PrimaryEffectID <= (int)cEntityEffect::effSaturation))
{
- PrimaryPotion = (cEntityEffect::eType)PrimaryPotionID;
+ PrimaryEffect = (cEntityEffect::eType)PrimaryEffectID;
}
- cEntityEffect::eType SecondaryPotion = cEntityEffect::effNoEffect;
- if ((SecondaryPotionID >= 0) && (SecondaryPotionID <= (int)cEntityEffect::effSaturation))
+ cEntityEffect::eType SecondaryEffect = cEntityEffect::effNoEffect;
+ if ((SecondaryEffectID >= 0) && (SecondaryEffectID <= (int)cEntityEffect::effSaturation))
{
- SecondaryPotion = (cEntityEffect::eType)SecondaryPotionID;
+ SecondaryEffect = (cEntityEffect::eType)SecondaryEffectID;
}
Window->SetSlot(*m_Player, 0, cItem());
- BeaconWindow->GetBeaconEntity()->SelectPrimaryPotion(PrimaryPotion);
- BeaconWindow->GetBeaconEntity()->SelectSecondaryPotion(SecondaryPotion);
+ BeaconWindow->GetBeaconEntity()->SelectPrimaryEffect(PrimaryEffect);
+ BeaconWindow->GetBeaconEntity()->SelectSecondaryEffect(SecondaryEffect);
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 8a68edd1f..8e31e211c 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -2590,8 +2590,8 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
Writer.AddInt("x", BeaconEntity.GetPosX());
Writer.AddInt("y", BeaconEntity.GetPosY());
Writer.AddInt("z", BeaconEntity.GetPosZ());
- Writer.AddInt("Primary", BeaconEntity.GetPrimaryPotion());
- Writer.AddInt("Secondary", BeaconEntity.GetSecondaryPotion());
+ Writer.AddInt("Primary", BeaconEntity.GetPrimaryEffect());
+ Writer.AddInt("Secondary", BeaconEntity.GetSecondaryEffect());
Writer.AddInt("Levels", BeaconEntity.GetBeaconLevel());
Writer.AddString("id", "Beacon"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
break;
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index aa129bfe8..8f4913030 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -863,8 +863,8 @@ void cBeaconWindow::OpenedByPlayer(cPlayer & a_Player)
super::OpenedByPlayer(a_Player);
a_Player.GetClientHandle()->SendWindowProperty(*this, 0, m_Beacon->GetBeaconLevel());
- a_Player.GetClientHandle()->SendWindowProperty(*this, 1, m_Beacon->GetPrimaryPotion());
- a_Player.GetClientHandle()->SendWindowProperty(*this, 2, m_Beacon->GetSecondaryPotion());
+ a_Player.GetClientHandle()->SendWindowProperty(*this, 1, m_Beacon->GetPrimaryEffect());
+ a_Player.GetClientHandle()->SendWindowProperty(*this, 2, m_Beacon->GetSecondaryEffect());
}
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 63387c33d..601cd8833 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -182,8 +182,8 @@ void cNBTChunkSerializer::AddBeaconEntity(cBeaconEntity * a_Entity)
m_Writer.BeginCompound("");
AddBasicTileEntity(a_Entity, "Beacon");
m_Writer.AddInt("Levels", a_Entity->GetBeaconLevel());
- m_Writer.AddInt("Primary", (int)a_Entity->GetPrimaryPotion());
- m_Writer.AddInt("Secondary", (int)a_Entity->GetSecondaryPotion());
+ m_Writer.AddInt("Primary", (int)a_Entity->GetPrimaryEffect());
+ m_Writer.AddInt("Secondary", (int)a_Entity->GetSecondaryEffect());
m_Writer.BeginList("Items", TAG_Compound);
AddItemGrid(a_Entity->GetContents());
m_Writer.EndList();
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 5a1972fd4..555ef410d 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -771,13 +771,13 @@ void cWSSAnvil::LoadBeaconFromNBT(cBlockEntityList & a_BlockEntities, const cPar
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Primary");
if (CurrentLine >= 0)
{
- Beacon->SelectPrimaryPotion((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
+ Beacon->SelectPrimaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
}
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Secondary");
if (CurrentLine >= 0)
{
- Beacon->SelectSecondaryPotion((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
+ Beacon->SelectSecondaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
}
// We are better than mojang, we load/save the beacon inventory!
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index ee47047a0..58f9e3cab 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -9,6 +9,7 @@
#include "zlib/zlib.h"
#include "json/json.h"
#include "../StringCompression.h"
+#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/DispenserEntity.h"
@@ -75,6 +76,7 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity)
const char * SaveInto = NULL;
switch (a_BlockEntity->GetBlockType())
{
+ case E_BLOCK_BEACON: SaveInto = "Beacons"; break;
case E_BLOCK_CHEST: SaveInto = "Chests"; break;
case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break;
case E_BLOCK_DROPPER: SaveInto = "Droppers"; break;
@@ -268,6 +270,24 @@ bool cWSSCompact::EraseChunkData(const cChunkCoords & a_Chunk)
void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWorld * a_World)
{
+ // Load beacon:
+ Json::Value AllBeacons = a_Value.get("Beacons", Json::nullValue);
+ if (!AllBeacons.empty())
+ {
+ for (Json::Value::iterator itr = AllBeacons.begin(); itr != AllBeacons.end(); ++itr)
+ {
+ std::auto_ptr BeaconEntity(new cBeaconEntity(0, 0, 0, a_World));
+ if (!BeaconEntity->LoadFromJson(*itr))
+ {
+ LOGWARNING("ERROR READING BEACON FROM JSON!");
+ }
+ else
+ {
+ a_BlockEntities.push_back(BeaconEntity.release());
+ }
+ } // for itr - AllBeacons[]
+ }
+
// Load chests:
Json::Value AllChests = a_Value.get("Chests", Json::nullValue);
if (!AllChests.empty())
From c49d4fd215170da29b5c285cc6a344ec102764c6 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 12:15:18 +0200
Subject: [PATCH 051/751] Updated documentation.
---
MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 10 +++++-----
src/BlockEntities/BeaconEntity.h | 6 +++---
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
index 294d47295..524087a8e 100644
--- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
+++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
@@ -63,16 +63,16 @@ return
{
IsActive = { Params = "", Return = "bool", Notes = "Is the beacon active?" },
GetBeaconLevel = { Params = "", Return = "number", Notes = "Returns the beacon level. (0 - 4)" },
- GetPrimaryPotion = { Params = "", Return = "EffectType", Notes = "Returns the primary potion." },
- GetSecondaryPotion = { Params = "", Return = "EffectType", Notes = "Returns the secondary potion." },
- SelectPrimaryPotion = { Params = "EffectType", Return = "bool", Notes = "Select the primary potion. Returns false when the potion is invalid." },
- SelectSecondaryPotion = { Params = "EffectType", Return = "bool", Notes = "Select the secondary potion. Returns false when the potion is invalid." },
+ GetPrimaryEffect = { Params = "", Return = "EffectType", Notes = "Returns the primary potion." },
+ GetSecondaryEffect = { Params = "", Return = "EffectType", Notes = "Returns the secondary potion." },
+ SelectPrimaryEffect = { Params = "EffectType", Return = "bool", Notes = "Select the primary effect. Returns false when the effect is invalid." },
+ SelectSecondaryEffect = { Params = "EffectType", Return = "bool", Notes = "Select the secondary effect. Returns false when the effect is invalid." },
CalculatePyramidLevel = { Params = "", Return = "number", Notes = "Calculate the amount of layers the pyramid below the beacon has." },
IsBeaconBlocked = { Params = "", Return = "bool", Notes = "Is the beacon blocked by non-transparent blocks that are higher than the beacon?" },
UpdateBeacon = { Params = "", Return = "", Notes = "Update the beacon." },
GiveEffects = { Params = "", Return = "", Notes = "Give the near-players the effects." },
IsMineralBlock = { Params = "BLOCKTYPE", Return = "bool", Notes = "Returns true if the block is a diamond block, a golden block, an iron block or an emerald block." },
- IsValidPotion = { Params = "EffectType", Return = "bool", Notes = "Returns true if the potion can be used." },
+ IsValidEffect = { Params = "EffectType", Return = "bool", Notes = "Returns true if the effect can be used." },
},
},
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index 5cf8da24e..cc8ee8ad2 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -55,10 +55,10 @@ public:
cEntityEffect::eType GetPrimaryEffect(void) const { return m_PrimaryEffect; }
cEntityEffect::eType GetSecondaryEffect(void) const { return m_SecondaryEffect; }
- /** Select the primary potion. Returns false when the potion is invalid.*/
+ /** Select the primary effect. Returns false when the effect is invalid.*/
bool SelectPrimaryEffect(cEntityEffect::eType a_Effect);
- /** Select the secondary potion. Returns false when the potion is invalid. */
+ /** Select the secondary effect. Returns false when the effect is invalid. */
bool SelectSecondaryEffect(cEntityEffect::eType a_Effect);
/** Calculate the amount of layers the pyramid below the beacon has. */
@@ -76,7 +76,7 @@ public:
/** Returns true if the block is a diamond block, a golden block, an iron block or an emerald block. */
static bool IsMineralBlock(BLOCKTYPE a_BlockType);
- /** Returns true if the potion can be used. */
+ /** Returns true if the effect can be used. */
static bool IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel);
// tolua_end
From 59adf113f0ba6414edf061fc4ffbf2bb2b904883 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Thu, 31 Jul 2014 17:22:48 +0200
Subject: [PATCH 052/751] MojangAPI: Moved the settings to a separate ini
section.
---
src/Protocol/MojangAPI.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 71a5e53de..fa99d63fd 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -120,8 +120,8 @@ cMojangAPI::~cMojangAPI()
void cMojangAPI::Start(cIniFile & a_SettingsIni)
{
- m_NameToUUIDServer = a_SettingsIni.GetValueSet("Authentication", "NameToUUIDServer", DEFAULT_NAME_TO_UUID_SERVER);
- m_NameToUUIDAddress = a_SettingsIni.GetValueSet("Authentication", "NameToUUIDAddress", DEFAULT_NAME_TO_UUID_ADDRESS);
+ m_NameToUUIDServer = a_SettingsIni.GetValueSet("MojangAPI", "NameToUUIDServer", DEFAULT_NAME_TO_UUID_SERVER);
+ m_NameToUUIDAddress = a_SettingsIni.GetValueSet("MojangAPI", "NameToUUIDAddress", DEFAULT_NAME_TO_UUID_ADDRESS);
LoadCachesFromDisk();
}
From 6b1f7e7a45ebc04f39bb54edc85fbe9c9d0659e7 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 18:15:39 +0200
Subject: [PATCH 053/751] Renamed "select..." methods to "set..." and better
IsValidEffect() function.
---
src/BlockEntities/BeaconEntity.cpp | 58 ++++++------------------------
src/BlockEntities/BeaconEntity.h | 8 ++---
src/ClientHandle.cpp | 4 +--
src/WorldStorage/WSSAnvil.cpp | 4 +--
4 files changed, 19 insertions(+), 55 deletions(-)
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index c94783ba8..55c5ccb7f 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -64,54 +64,18 @@ char cBeaconEntity::CalculatePyramidLevel(void)
bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel)
{
- if (a_Effect == cEntityEffect::effNoEffect)
+ switch (a_Effect)
{
- return true;
+ case cEntityEffect::effRegeneration: return (a_BeaconLevel >= 4);
+ case cEntityEffect::effStrength: return (a_BeaconLevel >= 3);
+ case cEntityEffect::effResistance: return (a_BeaconLevel >= 2);
+ case cEntityEffect::effJumpBoost: return (a_BeaconLevel >= 2);
+ case cEntityEffect::effSpeed: return (a_BeaconLevel >= 1);
+ case cEntityEffect::effHaste: return (a_BeaconLevel >= 1);
+ case cEntityEffect::effNoEffect: return true;
}
- switch (a_BeaconLevel)
- {
- case 4:
- {
- // Beacon level 4
- if (a_Effect == cEntityEffect::effRegeneration)
- {
- return true;
- }
- }
- case 3:
- {
- // Beacon level 3
- if (a_Effect == cEntityEffect::effStrength)
- {
- return true;
- }
- }
- case 2:
- {
- // Beacon level 2
- switch (a_Effect)
- {
- case cEntityEffect::effResistance:
- case cEntityEffect::effJumpBoost:
- {
- return true;
- }
- }
- }
- case 1:
- {
- // Beacon level 1
- switch (a_Effect)
- {
- case cEntityEffect::effSpeed:
- case cEntityEffect::effHaste:
- {
- return true;
- }
- }
- }
- }
+ LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, (int)a_Effect);
return false;
}
@@ -119,7 +83,7 @@ bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLe
-bool cBeaconEntity::SelectPrimaryEffect(cEntityEffect::eType a_Effect)
+bool cBeaconEntity::SetPrimaryEffect(cEntityEffect::eType a_Effect)
{
if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
@@ -140,7 +104,7 @@ bool cBeaconEntity::SelectPrimaryEffect(cEntityEffect::eType a_Effect)
-bool cBeaconEntity::SelectSecondaryEffect(cEntityEffect::eType a_Effect)
+bool cBeaconEntity::SetSecondaryEffect(cEntityEffect::eType a_Effect)
{
if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index cc8ee8ad2..0d7150aef 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -55,11 +55,11 @@ public:
cEntityEffect::eType GetPrimaryEffect(void) const { return m_PrimaryEffect; }
cEntityEffect::eType GetSecondaryEffect(void) const { return m_SecondaryEffect; }
- /** Select the primary effect. Returns false when the effect is invalid.*/
- bool SelectPrimaryEffect(cEntityEffect::eType a_Effect);
+ /** Sets the primary effect. Returns false when the effect is invalid. */
+ bool SetPrimaryEffect(cEntityEffect::eType a_Effect);
- /** Select the secondary effect. Returns false when the effect is invalid. */
- bool SelectSecondaryEffect(cEntityEffect::eType a_Effect);
+ /** Sets the secondary effect. Returns false when the effect is invalid. */
+ bool SetSecondaryEffect(cEntityEffect::eType a_Effect);
/** Calculate the amount of layers the pyramid below the beacon has. */
char CalculatePyramidLevel(void);
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index e833f338a..3ce506e1e 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -792,8 +792,8 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length)
}
Window->SetSlot(*m_Player, 0, cItem());
- BeaconWindow->GetBeaconEntity()->SelectPrimaryEffect(PrimaryEffect);
- BeaconWindow->GetBeaconEntity()->SelectSecondaryEffect(SecondaryEffect);
+ BeaconWindow->GetBeaconEntity()->SetPrimaryEffect(PrimaryEffect);
+ BeaconWindow->GetBeaconEntity()->SetSecondaryEffect(SecondaryEffect);
}
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 555ef410d..d3a156ee1 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -771,13 +771,13 @@ void cWSSAnvil::LoadBeaconFromNBT(cBlockEntityList & a_BlockEntities, const cPar
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Primary");
if (CurrentLine >= 0)
{
- Beacon->SelectPrimaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
+ Beacon->SetPrimaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
}
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Secondary");
if (CurrentLine >= 0)
{
- Beacon->SelectSecondaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
+ Beacon->SetSecondaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
}
// We are better than mojang, we load/save the beacon inventory!
From c138d19c31ee85a38fe758bc2c69591bcfe42230 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 18:16:52 +0200
Subject: [PATCH 054/751] Updated documentation again.
---
MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
index 524087a8e..90ebf12e6 100644
--- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
+++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
@@ -63,10 +63,10 @@ return
{
IsActive = { Params = "", Return = "bool", Notes = "Is the beacon active?" },
GetBeaconLevel = { Params = "", Return = "number", Notes = "Returns the beacon level. (0 - 4)" },
- GetPrimaryEffect = { Params = "", Return = "EffectType", Notes = "Returns the primary potion." },
- GetSecondaryEffect = { Params = "", Return = "EffectType", Notes = "Returns the secondary potion." },
- SelectPrimaryEffect = { Params = "EffectType", Return = "bool", Notes = "Select the primary effect. Returns false when the effect is invalid." },
- SelectSecondaryEffect = { Params = "EffectType", Return = "bool", Notes = "Select the secondary effect. Returns false when the effect is invalid." },
+ GetPrimaryEffect = { Params = "", Return = "EffectType", Notes = "Returns the primary effect." },
+ GetSecondaryEffect = { Params = "", Return = "EffectType", Notes = "Returns the secondary effect." },
+ SetPrimaryEffect = { Params = "EffectType", Return = "bool", Notes = "Select the primary effect. Returns false when the effect is invalid." },
+ SetSecondaryEffect = { Params = "EffectType", Return = "bool", Notes = "Select the secondary effect. Returns false when the effect is invalid." },
CalculatePyramidLevel = { Params = "", Return = "number", Notes = "Calculate the amount of layers the pyramid below the beacon has." },
IsBeaconBlocked = { Params = "", Return = "bool", Notes = "Is the beacon blocked by non-transparent blocks that are higher than the beacon?" },
UpdateBeacon = { Params = "", Return = "", Notes = "Update the beacon." },
From f47765dcbd8781d32f231d1ecdf4aac0b8c330ba Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 18:21:45 +0200
Subject: [PATCH 055/751] Added a default value to WaterSimulator,
LavaSimulator and RedstoneSimulator.
---
src/World.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/World.cpp b/src/World.cpp
index 348498693..b247a79bc 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -3176,7 +3176,7 @@ void cWorld::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicke
cRedstoneSimulator * cWorld::InitializeRedstoneSimulator(cIniFile & a_IniFile)
{
- AString SimulatorName = a_IniFile.GetValueSet("Physics", "RedstoneSimulator", "");
+ AString SimulatorName = a_IniFile.GetValueSet("Physics", "RedstoneSimulator", "incremental");
if (SimulatorName.empty())
{
@@ -3210,7 +3210,7 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
Printf(SimulatorNameKey, "%sSimulator", a_FluidName);
AString SimulatorSectionName;
Printf(SimulatorSectionName, "%sSimulator", a_FluidName);
- AString SimulatorName = a_IniFile.GetValueSet("Physics", SimulatorNameKey, "");
+ AString SimulatorName = a_IniFile.GetValueSet("Physics", SimulatorNameKey, "Vanilla");
if (SimulatorName.empty())
{
LOGWARNING("[Physics] %s not present or empty in %s, using the default of \"Vanilla\".", SimulatorNameKey.c_str(), GetIniFileName().c_str());
From bffad5043619d143d595806122dc625746126ed8 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 18:41:48 +0200
Subject: [PATCH 056/751] Fixed water from ice and removed packed ice drop.
---
src/Blocks/BlockIce.h | 14 ++++++++++++--
src/Items/ItemHandler.cpp | 1 +
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h
index c50623594..c085e9290 100644
--- a/src/Blocks/BlockIce.h
+++ b/src/Blocks/BlockIce.h
@@ -24,9 +24,19 @@ public:
}
- virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
- // TODO: Ice destroyed with air below it should turn into air instead of water
+ if (a_Player->IsGameModeCreative() || (a_BlockY <= 0))
+ {
+ return;
+ }
+
+ BLOCKTYPE BlockBelow = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ);
+ if (!cBlockInfo::IsSolid(BlockBelow) && !IsBlockLava(BlockBelow) && !IsBlockWater(BlockBelow))
+ {
+ return;
+ }
+
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_WATER, 0);
// This is called later than the real destroying of this ice block
}
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index d36b5d663..acfd1e648 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -578,6 +578,7 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
case E_BLOCK_LAPIS_BLOCK:
case E_BLOCK_SNOW:
case E_BLOCK_VINES:
+ case E_BLOCK_PACKED_ICE:
{
return false;
}
From ffd6797fe106c805646e2acfe5320594cc59ece4 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Thu, 31 Jul 2014 18:17:21 +0100
Subject: [PATCH 057/751] Comment suggestions
---
src/Mobs/Enderman.cpp | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index f1f366d3b..a32e4e175 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -22,7 +22,7 @@ public:
virtual bool Item(cPlayer * a_Player) override
{
- // Don't check players who are in creative gamemode.
+ // Don't check players who are in creative gamemode
if (a_Player->IsGameModeCreative())
{
return false;
@@ -30,13 +30,13 @@ public:
Vector3d Direction = m_EndermanPos - a_Player->GetPosition();
- // Don't check players who are more then 64 blocks away.
+ // Don't check players who are more then 64 blocks away
if (Direction.SqrLength() > 64)
{
return false;
}
- // Don't check if the player has a pumpkin on his head.
+ // Don't check if the player has a pumpkin on his head
if (a_Player->GetEquippedHelmet().m_ItemType == E_BLOCK_PUMPKIN)
{
return false;
@@ -46,9 +46,8 @@ public:
Vector3d LookVector = a_Player->GetLookVector();
double dot = Direction.Dot(LookVector);
- // 0.09 rad ~ 5 degrees.
- // If the players crosshair is within 5 degrees of the endermen
- // It counts as looking.
+ // 0.09 rad ~ 5 degrees
+ // If the player's crosshair is within 5 degrees of the enderman, it counts as looking
if (dot > cos(0.09))
{
return false;
@@ -119,17 +118,17 @@ void cEnderman::CheckEventSeePlayer()
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ);
- // Check if the chunk the enderman is in is lit.
+ // Check if the chunk the enderman is in is lit
if (!m_World->IsChunkLighted(ChunkX, ChunkZ))
{
m_World->QueueLightChunk(ChunkX, ChunkZ);
return;
}
- // Enderman only attack if the skylight is higher than 6
+ // Enderman only attack if the skylight is higher than 7
if (m_World->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) <= 7)
{
- // TODO: Teleport the enderman to a random spot.
+ // TODO: Teleport the enderman to a random spot
return;
}
From ecb86935f87ce2b9f1ae4671d8a8b722c798b8a2 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Thu, 31 Jul 2014 22:52:06 +0200
Subject: [PATCH 058/751] Fixed UUIDs handling in cPlayer.
The loading expected dashed UUIDs, MCS uses short UUIDs throughout.
---
src/Entities/Player.cpp | 13 ++++++++-----
src/Entities/Player.h | 2 +-
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index fcc8eb9a0..477334948 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1700,8 +1700,10 @@ bool cPlayer::LoadFromDisk(void)
// Load from the offline UUID file, if allowed:
AString OfflineUUID = cClientHandle::GenerateOfflineUUID(GetName());
+ const char * OfflineUsage = " (unused)";
if (cRoot::Get()->GetServer()->ShouldLoadOfflinePlayerData())
{
+ OfflineUsage = "";
if (LoadFromFile(GetUUIDFileName(OfflineUUID)))
{
return true;
@@ -1724,8 +1726,8 @@ bool cPlayer::LoadFromDisk(void)
}
// None of the files loaded successfully
- LOG("Player data file not found for %s (%s, offline %s), will be reset to defaults.",
- GetName().c_str(), m_UUID.c_str(), OfflineUUID.c_str()
+ LOG("Player data file not found for %s (%s, offline %s%s), will be reset to defaults.",
+ GetName().c_str(), m_UUID.c_str(), OfflineUUID.c_str(), OfflineUsage
);
return false;
}
@@ -2212,12 +2214,13 @@ void cPlayer::Detach()
AString cPlayer::GetUUIDFileName(const AString & a_UUID)
{
- ASSERT(a_UUID.size() == 36);
+ AString UUID = cMojangAPI::MakeUUIDDashed(a_UUID);
+ ASSERT(UUID.length() == 36);
AString res("players/");
- res.append(a_UUID, 0, 2);
+ res.append(UUID, 0, 2);
res.push_back('/');
- res.append(a_UUID, 2, AString::npos);
+ res.append(UUID, 2, AString::npos);
res.append(".json");
return res;
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 488884602..29bb4c39d 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -536,7 +536,7 @@ protected:
*/
bool m_bIsTeleporting;
- /** The UUID of the player, as read from the ClientHandle.
+ /** The short UUID (no dashes) of the player, as read from the ClientHandle.
If no ClientHandle is given, the UUID is initialized to empty. */
AString m_UUID;
From 70fd7caf1f879b0588042d6542c27ef8f0909a43 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Thu, 31 Jul 2014 22:54:45 +0200
Subject: [PATCH 059/751] Removed trailing whitespace.
---
src/Protocol/MojangAPI.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index fa99d63fd..45baa5a4f 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -245,7 +245,7 @@ AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
return a_UUID;
}
- case 36:
+ case 36:
{
// Remove the dashes from the string:
AString res;
@@ -277,7 +277,7 @@ AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID)
return a_UUID;
}
- case 32:
+ case 32:
{
// Insert dashes at the proper positions:
AString res;
From 84462ba8b20c28136c6a7923323f7cde28a86d70 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 23:04:00 +0200
Subject: [PATCH 060/751] Fixed hunger bugs, Implemented golden apple, added
jump statistic, added correct food effects.
---
src/ClientHandle.cpp | 4 ++-
src/Entities/EntityEffect.cpp | 2 +-
src/Entities/Player.cpp | 53 ++++++++++++++++++++++----------
src/Entities/Player.h | 5 +--
src/Items/ItemFood.h | 54 +++++++++++++++++++++++++++-----
src/Items/ItemGoldenApple.h | 58 +++++++++++++++++++++++++++++++++++
src/Items/ItemHandler.cpp | 33 +++++++++++++-------
src/Items/ItemHandler.h | 16 +++++-----
8 files changed, 177 insertions(+), 48 deletions(-)
create mode 100644 src/Items/ItemGoldenApple.h
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 30ec737be..bd76ef227 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -634,6 +634,7 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ,
if (!m_Player->IsSwimming())
{
+ m_Player->GetStatManager().AddValue(eStatistic::statJumps, 1);
m_Player->AddFoodExhaustion(m_Player->IsSprinting() ? 0.8 : 0.2);
}
}
@@ -1067,6 +1068,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
return;
}
+ m_Player->AddFoodExhaustion(0.025);
ItemHandler->OnBlockDestroyed(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ);
// The ItemHandler is also responsible for spawning the pickups
cChunkInterface ChunkInterface(World->GetChunkMap());
@@ -1212,7 +1214,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
else if ((ItemHandler->IsFood() || ItemHandler->IsDrinkable(EquippedDamage)))
{
if ((m_Player->IsSatiated() || m_Player->IsGameModeCreative()) &&
- ItemHandler->IsFood())
+ ItemHandler->IsFood() && (Equipped.m_ItemType != E_ITEM_GOLDEN_APPLE))
{
// The player is satiated or in creative, and trying to eat
return;
diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp
index fdcbe822e..39314f256 100644
--- a/src/Entities/EntityEffect.cpp
+++ b/src/Entities/EntityEffect.cpp
@@ -309,7 +309,7 @@ void cEntityEffectHunger::OnTick(cPawn & a_Target)
if (a_Target.IsPlayer())
{
cPlayer & Target = (cPlayer &) a_Target;
- Target.SetFoodExhaustionLevel(Target.GetFoodExhaustionLevel() + 0.025); // 0.5 per second = 0.025 per tick
+ Target.AddFoodExhaustion(0.025 * ((double)GetIntensity() + 1.0)); // 0.5 per second = 0.025 per tick
}
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 603fc7937..c9d885b89 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -545,7 +545,7 @@ void cPlayer::SetFoodTickTimer(int a_FoodTickTimer)
void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
{
- m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodExhaustionLevel, 4.0));
+ m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodExhaustionLevel, 40.0));
}
@@ -568,6 +568,18 @@ bool cPlayer::Feed(int a_Food, double a_Saturation)
+void cPlayer::AddFoodExhaustion(double a_Exhaustion)
+{
+ if (!IsGameModeCreative())
+ {
+ m_FoodExhaustionLevel = std::min(m_FoodExhaustionLevel + a_Exhaustion, 40.0);
+ }
+}
+
+
+
+
+
void cPlayer::FoodPoison(int a_NumTicks)
{
AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, 1);
@@ -1979,19 +1991,34 @@ void cPlayer::HandleFood(void)
return;
}
+ // Apply food exhaustion that has accumulated:
+ if (m_FoodExhaustionLevel > 4.0)
+ {
+ m_FoodExhaustionLevel -= 4.0;
+
+ if (m_FoodSaturationLevel > 0.0)
+ {
+ m_FoodSaturationLevel = std::max(m_FoodSaturationLevel - 1.0, 0.0);
+ }
+ else
+ {
+ SetFoodLevel(m_FoodLevel - 1);
+ }
+ }
+
// Heal or damage, based on the food level, using the m_FoodTickTimer:
- if ((m_FoodLevel > 17) || (m_FoodLevel <= 0))
+ if ((m_FoodLevel >= 18) || (m_FoodLevel <= 0))
{
m_FoodTickTimer++;
if (m_FoodTickTimer >= 80)
{
m_FoodTickTimer = 0;
- if ((m_FoodLevel > 17) && (GetHealth() < GetMaxHealth()))
+ if ((m_FoodLevel >= 18) && (GetHealth() < GetMaxHealth()))
{
// Regenerate health from food, incur 3 pts of food exhaustion:
Heal(1);
- m_FoodExhaustionLevel += 3.0;
+ AddFoodExhaustion(3.0);
}
else if ((m_FoodLevel <= 0) && (m_Health > 1))
{
@@ -2000,20 +2027,9 @@ void cPlayer::HandleFood(void)
}
}
}
-
- // Apply food exhaustion that has accumulated:
- if (m_FoodExhaustionLevel >= 4.0)
+ else
{
- m_FoodExhaustionLevel -= 4.0;
-
- if (m_FoodSaturationLevel >= 1.0)
- {
- m_FoodSaturationLevel -= 1.0;
- }
- else
- {
- SetFoodLevel(m_FoodLevel - 1);
- }
+ m_FoodTickTimer = 0;
}
}
@@ -2088,14 +2104,17 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos)
else if (IsSubmerged())
{
m_Stats.AddValue(statDistDove, Value);
+ AddFoodExhaustion(0.00015 * (double)Value);
}
else if (IsSwimming())
{
m_Stats.AddValue(statDistSwum, Value);
+ AddFoodExhaustion(0.00015 * (double)Value);
}
else if (IsOnGround())
{
m_Stats.AddValue(statDistWalked, Value);
+ AddFoodExhaustion((m_IsSprinting ? 0.001 : 0.0001) * (double)Value);
}
else
{
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 65c1e33a8..f188789b8 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -284,10 +284,7 @@ public:
bool Feed(int a_Food, double a_Saturation);
/** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */
- void AddFoodExhaustion(double a_Exhaustion)
- {
- m_FoodExhaustionLevel += a_Exhaustion;
- }
+ void AddFoodExhaustion(double a_Exhaustion);
/** Starts the food poisoning for the specified amount of ticks */
void FoodPoison(int a_NumTicks);
diff --git a/src/Items/ItemFood.h b/src/Items/ItemFood.h
index ff1d7991b..98050cad8 100644
--- a/src/Items/ItemFood.h
+++ b/src/Items/ItemFood.h
@@ -33,29 +33,69 @@ public:
case E_ITEM_BREAD: return FoodInfo(5, 6);
// Carrots handled in ItemSeeds
case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2);
- case E_ITEM_COOKED_FISH: return FoodInfo(5, 6);
+ case E_ITEM_COOKED_FISH: return FoodInfo(5, 6); // TODO: Add other fish types
case E_ITEM_COOKED_PORKCHOP: return FoodInfo(8, 12.8);
case E_ITEM_COOKIE: return FoodInfo(2, 0.4);
- case E_ITEM_GOLDEN_APPLE: return FoodInfo(4, 9.6);
+ // Golden apple handled in ItemGoldenApple
case E_ITEM_GOLDEN_CARROT: return FoodInfo(6, 14.4);
case E_ITEM_MELON_SLICE: return FoodInfo(2, 1.2);
case E_ITEM_MUSHROOM_SOUP: return FoodInfo(6, 7.2);
- case E_ITEM_POISONOUS_POTATO: return FoodInfo(2, 1.2, 60);
+ case E_ITEM_POISONOUS_POTATO: return FoodInfo(2, 1.2);
// Potatoes handled in ItemSeeds
case E_ITEM_PUMPKIN_PIE: return FoodInfo(8, 4.8);
case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8);
- case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2, 30);
+ case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2);
case E_ITEM_RAW_FISH: return FoodInfo(2, 1.2);
case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8);
case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4);
- case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8, 80);
- case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2, 100);
+ case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8);
+ case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2);
case E_ITEM_STEAK: return FoodInfo(8, 12.8);
}
LOGWARNING("%s: Unknown food item (%d), returning zero nutrition", __FUNCTION__, m_ItemType);
return FoodInfo(0, 0.f);
}
-
+
+ virtual bool GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance) override
+ {
+ switch (m_ItemType)
+ {
+ case E_ITEM_RAW_CHICKEN:
+ {
+ a_EffectType = cEntityEffect::effHunger;
+ a_EffectDurationTicks = 600;
+ a_EffectIntensity = 0;
+ a_Chance = 0.3f;
+ return true;
+ }
+ case E_ITEM_ROTTEN_FLESH:
+ {
+ a_EffectType = cEntityEffect::effHunger;
+ a_EffectDurationTicks = 600;
+ a_EffectIntensity = 0;
+ a_Chance = 0.8f;
+ return true;
+ }
+ case E_ITEM_SPIDER_EYE:
+ {
+ a_EffectType = cEntityEffect::effPoison;
+ a_EffectDurationTicks = 100;
+ a_EffectIntensity = 0;
+ a_Chance = 1.0f;
+ return true;
+ }
+ case E_ITEM_POISONOUS_POTATO:
+ {
+ a_EffectType = cEntityEffect::effPoison;
+ a_EffectDurationTicks = 100;
+ a_EffectIntensity = 0;
+ a_Chance = 0.6f;
+ return true;
+ }
+ }
+ return false;
+ }
+
};
diff --git a/src/Items/ItemGoldenApple.h b/src/Items/ItemGoldenApple.h
new file mode 100644
index 000000000..4e1096e65
--- /dev/null
+++ b/src/Items/ItemGoldenApple.h
@@ -0,0 +1,58 @@
+#pragma once
+
+#include "ItemFood.h"
+
+
+
+
+
+class cItemGoldenAppleHandler :
+ public cItemFoodHandler
+{
+ typedef cItemFoodHandler super;
+
+public:
+ cItemGoldenAppleHandler()
+ : super(E_ITEM_GOLDEN_APPLE)
+ {
+ }
+
+
+ virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
+ {
+ // Feed the player:
+ FoodInfo Info = GetFoodInfo();
+ a_Player->Feed(Info.FoodLevel, Info.Saturation);
+
+ // Add the effects:
+ a_Player->AddEntityEffect(cEntityEffect::effAbsorption, 2400, 0);
+ a_Player->AddEntityEffect(cEntityEffect::effRegeneration, 100, 1);
+
+ // When the apple is a 'notch apple', give extra effects:
+ if (a_Item->m_ItemDamage > 0)
+ {
+ a_Player->AddEntityEffect(cEntityEffect::effRegeneration, 600, 4);
+ a_Player->AddEntityEffect(cEntityEffect::effResistance, 6000, 0);
+ a_Player->AddEntityEffect(cEntityEffect::effFireResistance, 6000, 0);
+ }
+
+ return true;
+ }
+
+
+ virtual FoodInfo GetFoodInfo(void) override
+ {
+ return FoodInfo(4, 9.6);
+ }
+
+
+ virtual bool GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance) override
+ {
+ return false;
+ }
+
+};
+
+
+
+
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index d36b5d663..c7cc682ca 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -25,6 +25,7 @@
#include "ItemFishingRod.h"
#include "ItemFlowerPot.h"
#include "ItemFood.h"
+#include "ItemGoldenApple.h"
#include "ItemItemFrame.h"
#include "ItemHoe.h"
#include "ItemLeaves.h"
@@ -106,7 +107,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_BED: return new cItemBedHandler(a_ItemType);
case E_ITEM_BOAT: return new cItemBoatHandler(a_ItemType);
case E_ITEM_BOTTLE_O_ENCHANTING: return new cItemBottleOEnchantingHandler();
- case E_ITEM_BOW: return new cItemBowHandler;
+ case E_ITEM_BOW: return new cItemBowHandler();
case E_ITEM_BREWING_STAND: return new cItemBrewingStandHandler(a_ItemType);
case E_ITEM_CAKE: return new cItemCakeHandler(a_ItemType);
case E_ITEM_CAULDRON: return new cItemCauldronHandler(a_ItemType);
@@ -120,6 +121,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType);
case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
+ case E_ITEM_GOLDEN_APPLE: return new cItemGoldenAppleHandler();
case E_BLOCK_LILY_PAD: return new cItemLilypadHandler(a_ItemType);
case E_ITEM_MAP: return new cItemMapHandler();
case E_ITEM_MILK: return new cItemMilkHandler();
@@ -212,7 +214,6 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_COOKED_FISH:
case E_ITEM_COOKED_PORKCHOP:
case E_ITEM_COOKIE:
- case E_ITEM_GOLDEN_APPLE:
case E_ITEM_GOLDEN_CARROT:
case E_ITEM_MELON_SLICE:
case E_ITEM_MUSHROOM_SOUP:
@@ -618,29 +619,39 @@ bool cItemHandler::GetPlacementBlockTypeMeta(
+bool cItemHandler::GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance)
+{
+ return false;
+}
+
+
+
+
+
bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item)
{
UNUSED(a_Item);
-
- FoodInfo Info = GetFoodInfo();
+ FoodInfo Info = GetFoodInfo();
if ((Info.FoodLevel > 0) || (Info.Saturation > 0.f))
{
bool Success = a_Player->Feed(Info.FoodLevel, Info.Saturation);
-
- // If consumed and there's chance of foodpoisoning, do it:
- if (Success && (Info.PoisonChance > 0))
+
+ // Give effects
+ cEntityEffect::eType EffectType;
+ int EffectDurationTicks;
+ short EffectIntensity;
+ float Chance;
+ if (Success && GetEatEffect(EffectType, EffectDurationTicks, EffectIntensity, Chance))
{
cFastRandom r1;
- if ((r1.NextInt(100, a_Player->GetUniqueID()) - Info.PoisonChance) <= 0)
+ if (r1.NextFloat() < Chance)
{
- a_Player->FoodPoison(600); // Give the player food poisoning for 30 seconds.
+ a_Player->AddEntityEffect(EffectType, EffectDurationTicks, EffectIntensity, Chance);
}
}
-
return Success;
}
-
return false;
}
diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h
index 1d5f59f3e..8b554ee34 100644
--- a/src/Items/ItemHandler.h
+++ b/src/Items/ItemHandler.h
@@ -3,6 +3,7 @@
#include "../Defines.h"
#include "../Item.h"
+#include "../Entities/EntityEffect.h"
@@ -71,23 +72,24 @@ public:
struct FoodInfo
{
- double Saturation;
int FoodLevel;
- int PoisonChance; // 0 - 100, in percent. 0 = no chance of poisoning, 100 = sure poisoning
+ double Saturation;
FoodInfo(int a_FoodLevel, double a_Saturation, int a_PoisonChance = 0) :
- Saturation(a_Saturation),
FoodLevel(a_FoodLevel),
- PoisonChance(a_PoisonChance)
+ Saturation(a_Saturation)
{
}
} ;
- /** Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance) */
+ /** Returns the FoodInfo for this item. (FoodRecovery and Saturation) */
virtual FoodInfo GetFoodInfo();
-
+
+ /** If this function returns true, it sets the arguments to a effect who will be activated when you eat the item. */
+ virtual bool GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance);
+
/** Lets the player eat a selected item. Returns true if the player ate the item */
- virtual bool EatItem(cPlayer *a_Player, cItem *a_Item);
+ virtual bool EatItem(cPlayer * a_Player, cItem * a_Item);
/** Indicates if this item is a tool */
virtual bool IsTool(void);
From 87d195171a7069139cbbc9dfc2534ddd6c1ad867 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 23:08:08 +0200
Subject: [PATCH 061/751] Changed IsSolid to FullyOccupiesVoxel
---
src/Blocks/BlockIce.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h
index c085e9290..c38630fe3 100644
--- a/src/Blocks/BlockIce.h
+++ b/src/Blocks/BlockIce.h
@@ -32,7 +32,7 @@ public:
}
BLOCKTYPE BlockBelow = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ);
- if (!cBlockInfo::IsSolid(BlockBelow) && !IsBlockLava(BlockBelow) && !IsBlockWater(BlockBelow))
+ if (!cBlockInfo::FullyOccupiesVoxel(BlockBelow) && !IsBlockLiquid(BlockBelow))
{
return;
}
From cfaef0de386640fcc1729e6574fd481949bb6a3c Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 23:11:51 +0200
Subject: [PATCH 062/751] Capitalised "incremental"
---
src/World.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/World.cpp b/src/World.cpp
index b247a79bc..7500b163d 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -3176,17 +3176,17 @@ void cWorld::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicke
cRedstoneSimulator * cWorld::InitializeRedstoneSimulator(cIniFile & a_IniFile)
{
- AString SimulatorName = a_IniFile.GetValueSet("Physics", "RedstoneSimulator", "incremental");
+ AString SimulatorName = a_IniFile.GetValueSet("Physics", "RedstoneSimulator", "Incremental");
if (SimulatorName.empty())
{
- LOGWARNING("[Physics] RedstoneSimulator not present or empty in %s, using the default of \"incremental\".", GetIniFileName().c_str());
- SimulatorName = "incremental";
+ LOGWARNING("[Physics] RedstoneSimulator not present or empty in %s, using the default of \"Incremental\".", GetIniFileName().c_str());
+ SimulatorName = "Incremental";
}
cRedstoneSimulator * res = NULL;
- if (NoCaseCompare(SimulatorName, "incremental") == 0)
+ if (NoCaseCompare(SimulatorName, "Incremental") == 0)
{
res = new cIncrementalRedstoneSimulator(*this);
}
From 09b63565bcdd5977988d390f33de47b17cc7b7b7 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 23:19:05 +0200
Subject: [PATCH 063/751] Use "default:" in switch.
---
src/BlockEntities/BeaconEntity.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index 55c5ccb7f..805e5e61f 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -73,10 +73,13 @@ bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLe
case cEntityEffect::effSpeed: return (a_BeaconLevel >= 1);
case cEntityEffect::effHaste: return (a_BeaconLevel >= 1);
case cEntityEffect::effNoEffect: return true;
- }
- LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, (int)a_Effect);
- return false;
+ default:
+ {
+ LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, (int)a_Effect);
+ return false;
+ }
+ }
}
From 160fa3a9a9466da646bc7631543e813690f5a77d Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 31 Jul 2014 23:56:49 +0200
Subject: [PATCH 064/751] Import Statistics.h
---
src/ClientHandle.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index bd76ef227..79ec8c9b6 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -3,6 +3,7 @@
#include "ClientHandle.h"
#include "Server.h"
#include "World.h"
+#include "Statistics.h"
#include "Entities/Pickup.h"
#include "Bindings/PluginManager.h"
#include "Entities/Player.h"
From 86d84bcb7391b6a862b53436623b97140529aa83 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 1 Aug 2014 17:29:17 +0200
Subject: [PATCH 065/751] Compile fix.
---
src/ClientHandle.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 79ec8c9b6..2d665a06c 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -3,7 +3,6 @@
#include "ClientHandle.h"
#include "Server.h"
#include "World.h"
-#include "Statistics.h"
#include "Entities/Pickup.h"
#include "Bindings/PluginManager.h"
#include "Entities/Player.h"
@@ -635,7 +634,7 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ,
if (!m_Player->IsSwimming())
{
- m_Player->GetStatManager().AddValue(eStatistic::statJumps, 1);
+ m_Player->GetStatManager().AddValue(statJumps, 1);
m_Player->AddFoodExhaustion(m_Player->IsSprinting() ? 0.8 : 0.2);
}
}
From bfe11024ac9bf202baa49a88d9370738ab0fcb8b Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 1 Aug 2014 19:37:08 +0200
Subject: [PATCH 066/751] Added missing HOOK_BLOCK_SPREAD call.
---
src/Simulator/FireSimulator.cpp | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp
index 69dc7164e..cdb5abde2 100644
--- a/src/Simulator/FireSimulator.cpp
+++ b/src/Simulator/FireSimulator.cpp
@@ -359,18 +359,26 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel
continue;
}
+ int AbsX = (Neighbour->GetPosX() * cChunkDef::Width) + X;
+ int Y = a_RelY + gNeighborCoords[i].y;
+ int AbsZ = (Neighbour->GetPosZ() * cChunkDef::Width) + Z;
+
if (BlockType == E_BLOCK_TNT)
{
- int AbsX = X + Neighbour->GetPosX() * cChunkDef::Width;
- int AbsZ = Z + Neighbour->GetPosZ() * cChunkDef::Width;
-
- m_World.SpawnPrimedTNT(AbsX, a_RelY + gNeighborCoords[i].y, AbsZ, 0);
- Neighbour->SetBlock(X, a_RelY + gNeighborCoords[i].y, Z, E_BLOCK_AIR, 0);
+ m_World.SpawnPrimedTNT(AbsX, Y, AbsZ, 0);
+ Neighbour->SetBlock(X, a_RelY + Y, Z, E_BLOCK_AIR, 0);
return;
}
bool ShouldReplaceFuel = (m_World.GetTickRandomNumber(MAX_CHANCE_REPLACE_FUEL) < m_ReplaceFuelChance);
- Neighbour->SetBlock(X, a_RelY + gNeighborCoords[i].y, Z, ShouldReplaceFuel ? E_BLOCK_FIRE : E_BLOCK_AIR, 0);
+ if (ShouldReplaceFuel && !cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, AbsX, Y, AbsZ, ssFireSpread))
+ {
+ Neighbour->SetBlock(X, Y, Z, E_BLOCK_FIRE, 0);
+ }
+ else
+ {
+ Neighbour->SetBlock(X, Y, Z, E_BLOCK_AIR, 0);
+ }
} // for i - Coords[]
}
From c865fc8ca501e7405da2ce8353628373e4526053 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Fri, 1 Aug 2014 22:05:40 +0100
Subject: [PATCH 067/751] Improved endermen code a little
---
MCServer/monsters.ini | 2 +-
src/Mobs/Enderman.cpp | 68 +++++++++++++++++++++++++++++++------------
src/Mobs/Enderman.h | 4 +++
src/Mobs/Monster.cpp | 4 ++-
4 files changed, 57 insertions(+), 21 deletions(-)
diff --git a/MCServer/monsters.ini b/MCServer/monsters.ini
index b631fc1a9..d29b01d8f 100644
--- a/MCServer/monsters.ini
+++ b/MCServer/monsters.ini
@@ -44,7 +44,7 @@ MaxHealth=10
AttackRange=2.0
AttackRate=1
AttackDamage=4.0
-SightDistance=25.0
+SightDistance=64.0
MaxHealth=40
[ZombiePigman]
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index a32e4e175..1dc73d654 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -14,9 +14,10 @@ class cPlayerLookCheck :
public cPlayerListCallback
{
public:
- cPlayerLookCheck(Vector3d a_EndermanPos) :
+ cPlayerLookCheck(Vector3d a_EndermanPos, int a_SightDistance) :
m_Player(NULL),
- m_EndermanPos(a_EndermanPos)
+ m_EndermanPos(a_EndermanPos),
+ m_SightDistance(a_SightDistance)
{
}
@@ -30,8 +31,8 @@ public:
Vector3d Direction = m_EndermanPos - a_Player->GetPosition();
- // Don't check players who are more then 64 blocks away
- if (Direction.SqrLength() > 64)
+ // Don't check players who are more then SightDistance (64) blocks away
+ if (Direction.Length() > m_SightDistance)
{
return false;
}
@@ -48,7 +49,7 @@ public:
// 0.09 rad ~ 5 degrees
// If the player's crosshair is within 5 degrees of the enderman, it counts as looking
- if (dot > cos(0.09))
+ if (dot <= cos(0.09))
{
return false;
}
@@ -69,6 +70,7 @@ public:
protected:
cPlayer * m_Player;
Vector3d m_EndermanPos;
+ int m_SightDistance;
} ;
@@ -107,7 +109,7 @@ void cEnderman::CheckEventSeePlayer()
return;
}
- cPlayerLookCheck Callback(GetPosition());
+ cPlayerLookCheck Callback(GetPosition(), m_SightDistance);
if (m_World->ForEachPlayer(Callback))
{
return;
@@ -115,20 +117,10 @@ void cEnderman::CheckEventSeePlayer()
ASSERT(Callback.GetPlayer() != NULL);
- int ChunkX, ChunkZ;
- cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ);
-
- // Check if the chunk the enderman is in is lit
- if (!m_World->IsChunkLighted(ChunkX, ChunkZ))
+ if (!CheckLight())
{
- m_World->QueueLightChunk(ChunkX, ChunkZ);
- return;
- }
-
- // Enderman only attack if the skylight is higher than 7
- if (m_World->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) <= 7)
- {
- // TODO: Teleport the enderman to a random spot
+ // Insufficient light for enderman to become aggravated
+ // TODO: Teleport to a suitable location
return;
}
@@ -140,6 +132,19 @@ void cEnderman::CheckEventSeePlayer()
GetWorld()->BroadcastEntityMetadata(*this);
}
}
+
+
+
+
+
+void cEnderman::CheckEventLostPlayer(void)
+{
+ super::CheckEventLostPlayer();
+ if (!CheckLight())
+ {
+ EventLosePlayer();
+ }
+}
@@ -151,3 +156,28 @@ void cEnderman::EventLosePlayer()
m_bIsScreaming = false;
GetWorld()->BroadcastEntityMetadata(*this);
}
+
+
+
+
+
+bool cEnderman::CheckLight()
+{
+ int ChunkX, ChunkZ;
+ cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ);
+
+ // Check if the chunk the enderman is in is lit
+ if (!m_World->IsChunkLighted(ChunkX, ChunkZ))
+ {
+ m_World->QueueLightChunk(ChunkX, ChunkZ);
+ return true;
+ }
+
+ // Enderman only attack if the skylight is lower or equal to 8
+ if (m_World->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) - GetWorld()->GetSkyDarkness() > 8)
+ {
+ return false;
+ }
+
+ return true;
+}
diff --git a/src/Mobs/Enderman.h b/src/Mobs/Enderman.h
index da857ee09..4583746e7 100644
--- a/src/Mobs/Enderman.h
+++ b/src/Mobs/Enderman.h
@@ -19,12 +19,16 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void CheckEventSeePlayer(void) override;
+ virtual void CheckEventLostPlayer(void) override;
virtual void EventLosePlayer(void) override;
bool IsScreaming(void) const {return m_bIsScreaming; }
BLOCKTYPE GetCarriedBlock(void) const {return CarriedBlock; }
NIBBLETYPE GetCarriedMeta(void) const {return CarriedMeta; }
+ /** Returns if the current sky light level is sufficient for the enderman to become aggravated */
+ bool CheckLight(void);
+
private:
bool m_bIsScreaming;
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 622a67816..94df991a3 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -276,7 +276,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
if (DoesPosYRequireJump((int)floor(m_Destination.y)))
{
m_bOnGround = false;
- AddSpeedY(5.2); // Jump!!
+
+ // TODO: Change to AddSpeedY once collision detection is fixed - currently, mobs will go into blocks attempting to jump without a teleport
+ AddPosY(1.2); // Jump!!
}
}
From b5c0a4aa3ac904a7db1ee23e92a73dad6e1d4ade Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Fri, 1 Aug 2014 22:15:14 +0100
Subject: [PATCH 068/751] Fixed issues with autocomplete and time loading
* Fixes #1274
---
src/World.cpp | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/src/World.cpp b/src/World.cpp
index 865ddfcc6..d2213d1e5 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -578,8 +578,7 @@ void cWorld::Start(void)
m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true);
int GameMode = IniFile.GetValueSetI("General", "Gamemode", (int)m_GameMode);
int Weather = IniFile.GetValueSetI("General", "Weather", (int)m_Weather);
- m_TimeOfDay = IniFile.GetValueSetI("General", "TimeInTicks", m_TimeOfDay);
-
+
if (GetDimension() == dimOverworld)
{
m_NetherWorldName = IniFile.GetValueSet("LinkedWorlds", "NetherWorldName", GetName() + "_nether");
@@ -597,6 +596,7 @@ void cWorld::Start(void)
InitialiseGeneratorDefaults(IniFile);
InitialiseAndLoadMobSpawningValues(IniFile);
+ SetTimeOfDay(IniFile.GetValueSetI("General", "TimeInTicks", m_TimeOfDay));
m_ChunkMap = new cChunkMap(this);
@@ -3153,21 +3153,47 @@ int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProje
void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Results)
{
+ typedef std::pair pair_t;
+ size_t LastSpace = a_Text.find_last_of(" "); // Find the position of the last space
+ AString LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); // Find the last word
+
+ if (LastWord.empty())
+ {
+ return;
+ }
+
+ std::vector UsernamesByWeight;
+
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr)
{
- size_t LastSpace = a_Text.find_last_of(" "); // Find the position of the last space
-
- AString LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); // Find the last word
AString PlayerName ((*itr)->GetName());
- size_t Found = PlayerName.find(LastWord); // Try to find last word in playername
+ AString::size_type Found = PlayerName.find(LastWord); // Try to find last word in playername
if (Found == AString::npos)
{
continue; // No match
}
- a_Results.push_back(PlayerName); // Match!
+ UsernamesByWeight.push_back(std::make_pair(Found, PlayerName)); // Match! Store it with the position of the match as a weight
+ }
+ Lock.Unlock();
+
+ std::sort(UsernamesByWeight.begin(), UsernamesByWeight.end()); // Sort lexicographically (by the first value, then second), so higher weights (usernames with match closer to start) come first (#1274)
+
+ /* TODO: Uncomment once migrated to C++11
+ std::transform(
+ UsernamesByWeight.begin(),
+ UsernamesByWeight.end(),
+ std::back_inserter(a_Results),
+ [](const pair_t & p) { return p.first; }
+ );
+ */
+
+ a_Results.reserve(UsernamesByWeight.size());
+ for (std::vector::const_iterator itr = UsernamesByWeight.begin(); itr != UsernamesByWeight.end(); ++itr)
+ {
+ a_Results.push_back(itr->second);
}
}
From 3b4255dbfe6dc0fa2ecd861221a2ed5b124a81ad Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 2 Aug 2014 00:14:05 +0200
Subject: [PATCH 069/751] Fixed a bug who can used from hacked clients.
---
src/BlockEntities/BeaconEntity.cpp | 2 ++
src/ClientHandle.cpp | 17 ++++++++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index 805e5e61f..dcf659f47 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -90,6 +90,7 @@ bool cBeaconEntity::SetPrimaryEffect(cEntityEffect::eType a_Effect)
{
if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
+ m_PrimaryEffect = cEntityEffect::effNoEffect;
return false;
}
@@ -111,6 +112,7 @@ bool cBeaconEntity::SetSecondaryEffect(cEntityEffect::eType a_Effect)
{
if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
+ m_SecondaryEffect = cEntityEffect::effNoEffect;
return false;
}
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index d71c6a9d8..72257028a 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -795,7 +795,22 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length)
Window->SetSlot(*m_Player, 0, cItem());
BeaconWindow->GetBeaconEntity()->SetPrimaryEffect(PrimaryEffect);
- BeaconWindow->GetBeaconEntity()->SetSecondaryEffect(SecondaryEffect);
+
+ // Valid effect check. Vanilla don't check this, but we do it :)
+ if (
+ (SecondaryEffect == cEntityEffect::effNoEffect) ||
+ (SecondaryEffect == cEntityEffect::effRegeneration) ||
+ (SecondaryEffect == BeaconWindow->GetBeaconEntity()->GetPrimaryEffect())
+ )
+ {
+ BeaconWindow->GetBeaconEntity()->SetSecondaryEffect(SecondaryEffect);
+ }
+ else
+ {
+ BeaconWindow->GetBeaconEntity()->SetSecondaryEffect(cEntityEffect::effNoEffect);
+ }
+
+ m_Player->CloseWindow(true);
}
From a44fbf2338e98e81bbc55780c92fa8780b061f9f Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sat, 2 Aug 2014 21:44:16 +0200
Subject: [PATCH 070/751] Added proper trees and height for SwamplandM biome
---
src/Generating/HeiGen.cpp | 2 +-
src/Generating/Trees.cpp | 2 +-
src/Generating/Trees.h | 2 ++
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp
index 870ceef7f..ba11b31b4 100644
--- a/src/Generating/HeiGen.cpp
+++ b/src/Generating/HeiGen.cpp
@@ -432,7 +432,7 @@ const cHeiGenBiomal::sGenParam cHeiGenBiomal::m_GenParam[256] =
/* biExtremeHillsM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 131
/* biFlowerForest */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 132
/* biTaigaM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 133
- /* biSwamplandM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 134
+ /* biSwamplandM */ { 1.0f, 2.0f, 1.10f, 5.0f, 0.01f, 8.0f, 60}, // 134
// Biomes 135 .. 139 unused, 5 empty placeholders here:
{}, {}, {}, {}, {}, // 135 .. 139
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index 32594d0b4..1b0f2dc14 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -181,6 +181,7 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No
return;
}
+ case biSwamplandM:
case biSwampland:
{
// Swamp trees:
@@ -233,7 +234,6 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No
case biExtremeHillsM:
case biFlowerForest:
case biTaigaM:
- case biSwamplandM:
case biIcePlainsSpikes:
case biJungleM:
case biJungleEdgeM:
diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h
index 1f6ac4dff..c9eb7de80 100644
--- a/src/Generating/Trees.h
+++ b/src/Generating/Trees.h
@@ -28,6 +28,7 @@ logs can overwrite others(leaves), but others shouldn't overwrite logs. This is
#define CASE_TREE_ALLOWED_BLOCKS \
case E_BLOCK_AIR: \
case E_BLOCK_LEAVES: \
+ case E_BLOCK_NEW_LEAVES: \
case E_BLOCK_SNOW: \
case E_BLOCK_TALL_GRASS: \
case E_BLOCK_DEAD_BUSH: \
@@ -40,6 +41,7 @@ logs can overwrite others(leaves), but others shouldn't overwrite logs. This is
/* case E_BLOCK_LEAVES: LEAVES are a special case, they can be overwritten only by log. Handled in cChunkMap::ReplaceTreeBlocks(). */ \
case E_BLOCK_SNOW: \
case E_BLOCK_TALL_GRASS: \
+ case E_BLOCK_BIG_FLOWER: \
case E_BLOCK_DEAD_BUSH: \
case E_BLOCK_SAPLING: \
case E_BLOCK_VINES
From 7915c4ca7cf4a7afaa86e62757d23364ead4c69e Mon Sep 17 00:00:00 2001
From: archshift
Date: Sat, 2 Aug 2014 21:44:02 -0700
Subject: [PATCH 071/751] Entity.cpp: On portal check, use if-else for current
dimension
If current dimension corresponds with the portal (nether portal in the nether) send to the overworld, else send to the portal dimension. No need to switch on the dimension and exclude potential others.
---
src/Entities/Entity.cpp | 122 +++++++++++++++++++---------------------
1 file changed, 58 insertions(+), 64 deletions(-)
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index da578013d..c2727e6a1 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1068,42 +1068,38 @@ bool cEntity::DetectPortal()
}
m_PortalCooldownData.m_TicksDelayed = 0;
- switch (GetWorld()->GetDimension())
+ if (GetWorld()->GetDimension() == dimNether)
{
- case dimNether:
+ if (GetWorld()->GetLinkedOverworldName().empty())
{
- if (GetWorld()->GetLinkedOverworldName().empty())
- {
- return false;
- }
-
- m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
-
- if (IsPlayer())
- {
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimOverworld); // Send a respawn packet before world is loaded/generated so the client isn't left in limbo
- }
-
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
+ return false;
}
- case dimOverworld:
+
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
+
+ if (IsPlayer())
{
- if (GetWorld()->GetNetherWorldName().empty())
- {
- return false;
- }
-
- m_PortalCooldownData.m_ShouldPreventTeleportation = true;
-
- if (IsPlayer())
- {
- ((cPlayer *)this)->AwardAchievement(achEnterPortal);
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimNether);
- }
-
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName(), dimNether, GetWorld()->GetName()), false);
+ ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimOverworld); // Send a respawn packet before world is loaded/generated so the client isn't left in limbo
}
- default: return false;
+
+ return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
+ }
+ else
+ {
+ if (GetWorld()->GetNetherWorldName().empty())
+ {
+ return false;
+ }
+
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
+
+ if (IsPlayer())
+ {
+ ((cPlayer *)this)->AwardAchievement(achEnterPortal);
+ ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimNether);
+ }
+
+ return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName(), dimNether, GetWorld()->GetName()), false);
}
}
case E_BLOCK_END_PORTAL:
@@ -1113,45 +1109,43 @@ bool cEntity::DetectPortal()
return false;
}
- switch (GetWorld()->GetDimension())
+ if (GetWorld()->GetDimension() == dimEnd)
{
- case dimEnd:
+
+ if (GetWorld()->GetLinkedOverworldName().empty())
{
- if (GetWorld()->GetLinkedOverworldName().empty())
- {
- return false;
- }
-
- m_PortalCooldownData.m_ShouldPreventTeleportation = true;
-
- if (IsPlayer())
- {
- cPlayer * Player = (cPlayer *)this;
- Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z);
- Player->GetClientHandle()->SendRespawn(dimOverworld);
- }
-
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
+ return false;
}
- case dimOverworld:
+
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
+
+ if (IsPlayer())
{
- if (GetWorld()->GetEndWorldName().empty())
- {
- return false;
- }
-
- m_PortalCooldownData.m_ShouldPreventTeleportation = true;
-
- if (IsPlayer())
- {
- ((cPlayer *)this)->AwardAchievement(achEnterTheEnd);
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimEnd);
- }
-
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName(), dimEnd, GetWorld()->GetName()), false);
+ cPlayer * Player = (cPlayer *)this;
+ Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z);
+ Player->GetClientHandle()->SendRespawn(dimOverworld);
}
- default: return false;
+
+ return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
}
+ else
+ {
+ if (GetWorld()->GetEndWorldName().empty())
+ {
+ return false;
+ }
+
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
+
+ if (IsPlayer())
+ {
+ ((cPlayer *)this)->AwardAchievement(achEnterTheEnd);
+ ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimEnd);
+ }
+
+ return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName(), dimEnd, GetWorld()->GetName()), false);
+ }
+
}
default: break;
}
From 3ffec92e7930c0b4bb14073f23a9d12313bd6cbc Mon Sep 17 00:00:00 2001
From: archshift
Date: Sat, 2 Aug 2014 22:27:27 -0700
Subject: [PATCH 072/751] Removed unused cPlayer::FoodPoison function
---
src/Entities/Player.cpp | 9 ---------
src/Entities/Player.h | 3 ---
2 files changed, 12 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index ca3b1f367..d3d5a61d4 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -580,15 +580,6 @@ void cPlayer::AddFoodExhaustion(double a_Exhaustion)
-void cPlayer::FoodPoison(int a_NumTicks)
-{
- AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, 1);
-}
-
-
-
-
-
void cPlayer::StartEating(void)
{
// Set the timer:
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 917e87a89..e3203d6d1 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -286,9 +286,6 @@ public:
/** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */
void AddFoodExhaustion(double a_Exhaustion);
- /** Starts the food poisoning for the specified amount of ticks */
- void FoodPoison(int a_NumTicks);
-
/** Returns true if the player is currently in the process of eating the currently equipped item */
bool IsEating(void) const { return (m_EatingFinishTick >= 0); }
From 9ecce2366e81ae66c77312220e378ff2f1b02a24 Mon Sep 17 00:00:00 2001
From: archshift
Date: Sat, 2 Aug 2014 22:35:29 -0700
Subject: [PATCH 073/751] Code reduction and clarity fixes
---
src/Entities/Entity.cpp | 28 +++++++++-------------------
src/Entities/Player.cpp | 17 +++++++----------
2 files changed, 16 insertions(+), 29 deletions(-)
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index c2727e6a1..042e3b868 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -543,10 +543,7 @@ void cEntity::KilledBy(TakeDamageInfo & a_TDI)
void cEntity::Heal(int a_HitPoints)
{
m_Health += a_HitPoints;
- if (m_Health > m_MaxHealth)
- {
- m_Health = m_MaxHealth;
- }
+ m_Health = std::min(m_Health, m_MaxHealth);
}
@@ -555,7 +552,7 @@ void cEntity::Heal(int a_HitPoints)
void cEntity::SetHealth(int a_Health)
{
- m_Health = std::max(0, std::min(m_MaxHealth, a_Health));
+ m_Health = Clamp(a_Health, 0, m_MaxHealth);
}
@@ -1264,10 +1261,10 @@ void cEntity::HandleAir(void)
SetSpeedY(1); // Float in the water
}
- // Either reduce air level or damage player
- if (m_AirLevel < 1)
+ if (m_AirLevel <= 0)
{
- if (m_AirTickTimer < 1)
+ // Either reduce air level or damage player
+ if (m_AirTickTimer <= 0)
{
// Damage player
TakeDamage(dtDrowning, NULL, 1, 1, 0);
@@ -1552,17 +1549,10 @@ void cEntity::SetHeight(double a_Height)
void cEntity::SetMass(double a_Mass)
{
- if (a_Mass > 0)
- {
- m_Mass = a_Mass;
- }
- else
- {
- // Make sure that mass is not zero. 1g is the default because we
- // have to choose a number. It's perfectly legal to have a mass
- // less than 1g as long as is NOT equal or less than zero.
- m_Mass = 0.001;
- }
+ // Make sure that mass is not zero. 1g is the default because we
+ // have to choose a number. It's perfectly legal to have a mass
+ // less than 1g as long as is NOT equal or less than zero.
+ m_Mass = std::max(a_Mass, 0.001);
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index d3d5a61d4..d1d7349a6 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -527,7 +527,7 @@ void cPlayer::SetFoodLevel(int a_FoodLevel)
void cPlayer::SetFoodSaturationLevel(double a_FoodSaturationLevel)
{
- m_FoodSaturationLevel = std::max(0.0, std::min(a_FoodSaturationLevel, (double)m_FoodLevel));
+ m_FoodSaturationLevel = Clamp(a_FoodSaturationLevel, 0.0, (double) m_FoodLevel);
}
@@ -545,7 +545,7 @@ void cPlayer::SetFoodTickTimer(int a_FoodTickTimer)
void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
{
- m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodExhaustionLevel, 40.0));
+ m_FoodExhaustionLevel = Clamp(a_FoodExhaustionLevel, 0.0, 40.0);
}
@@ -700,16 +700,13 @@ double cPlayer::GetMaxSpeed(void) const
{
return m_FlyingMaxSpeed;
}
+ else if (m_IsSprinting)
+ {
+ return m_SprintingMaxSpeed;
+ }
else
{
- if (m_IsSprinting)
- {
- return m_SprintingMaxSpeed;
- }
- else
- {
- return m_NormalMaxSpeed;
- }
+ return m_NormalMaxSpeed;
}
}
From e461df00302939cd767ae0c6a31ce22fc94e977c Mon Sep 17 00:00:00 2001
From: archshift
Date: Sun, 3 Aug 2014 02:20:48 -0700
Subject: [PATCH 074/751] Entity.cpp: Air timer comment fix
---
src/Entities/Entity.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 042e3b868..a274e6780 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1263,7 +1263,7 @@ void cEntity::HandleAir(void)
if (m_AirLevel <= 0)
{
- // Either reduce air level or damage player
+ // Runs the air tick timer to check whether the player should be damaged
if (m_AirTickTimer <= 0)
{
// Damage player
From dd9a19e3952ce48fe8d3ad4825889f17c69ac55a Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sun, 3 Aug 2014 15:31:59 +0200
Subject: [PATCH 075/751] VillageGen: Fixed a typo in comment
---
src/Generating/VillageGen.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp
index cade923c9..a7f66b75e 100644
--- a/src/Generating/VillageGen.cpp
+++ b/src/Generating/VillageGen.cpp
@@ -168,7 +168,7 @@ protected:
/** The density for this village. Used to refrain from populating all house connectors. Range [0, 100] */
int m_Density;
- /** Borders of the vilalge - no item may reach out of this cuboid. */
+ /** Borders of the village - no item may reach out of this cuboid. */
cCuboid m_Borders;
/** Prefabs to use for buildings */
From 6ce61d1a6fd912c99284875a9052475e06fba432 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 11:57:05 +0200
Subject: [PATCH 076/751] Fixed a ToLua warning - operator = not supported.
---
src/BlockID.cpp | 2 +-
src/Cuboid.cpp | 2 +-
src/Cuboid.h | 6 +++++-
src/Entities/EntityEffect.cpp | 2 +-
src/Entities/EntityEffect.h | 2 +-
src/Globals.h | 4 ++--
src/Matrix4.h | 4 ++++
src/WorldStorage/WorldStorage.h | 2 +-
8 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/BlockID.cpp b/src/BlockID.cpp
index d145a2e5b..07a1fc9e5 100644
--- a/src/BlockID.cpp
+++ b/src/BlockID.cpp
@@ -17,7 +17,7 @@ class cBlockIDMap
// Making the map case-insensitive:
struct Comparator
{
- bool operator()(const AString & a_Item1, const AString & a_Item2) const
+ bool operator ()(const AString & a_Item1, const AString & a_Item2) const
{
return (NoCaseCompare(a_Item1, a_Item2) > 0);
}
diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp
index 26e86c77b..8891cfcb1 100644
--- a/src/Cuboid.cpp
+++ b/src/Cuboid.cpp
@@ -24,7 +24,7 @@ static bool DoIntervalsIntersect(int a_Min1, int a_Max1, int a_Min2, int a_Max2)
////////////////////////////////////////////////////////////////////////////////
// cCuboid:
-cCuboid & cCuboid::operator=(cCuboid a_Other)
+cCuboid & cCuboid::operator =(cCuboid a_Other)
{
std::swap(p1, a_Other.p1);
std::swap(p2, a_Other.p2);
diff --git a/src/Cuboid.h b/src/Cuboid.h
index d62cf8063..c205156ec 100644
--- a/src/Cuboid.h
+++ b/src/Cuboid.h
@@ -20,7 +20,11 @@ public:
cCuboid(int a_X1, int a_Y1, int a_Z1) : p1(a_X1, a_Y1, a_Z1), p2(a_X1, a_Y1, a_Z1) {}
cCuboid(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) : p1(a_X1, a_Y1, a_Z1), p2(a_X2, a_Y2, a_Z2) {}
- cCuboid & operator=(cCuboid a_Other);
+ // tolua_end
+
+ cCuboid & operator =(cCuboid a_Other);
+
+ // tolua_begin
void Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2);
void Assign(const cCuboid & a_SrcCuboid);
diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp
index 39314f256..3e28392f4 100644
--- a/src/Entities/EntityEffect.cpp
+++ b/src/Entities/EntityEffect.cpp
@@ -170,7 +170,7 @@ cEntityEffect::cEntityEffect(const cEntityEffect & a_OtherEffect):
-cEntityEffect & cEntityEffect::operator=(cEntityEffect a_OtherEffect)
+cEntityEffect & cEntityEffect::operator =(cEntityEffect a_OtherEffect)
{
std::swap(m_Ticks, a_OtherEffect.m_Ticks);
std::swap(m_Duration, a_OtherEffect.m_Duration);
diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h
index f9c1e4eb2..47c298f57 100644
--- a/src/Entities/EntityEffect.h
+++ b/src/Entities/EntityEffect.h
@@ -71,7 +71,7 @@ public:
/** Creates an entity effect by copying another
@param a_OtherEffect The other effect to copy */
- cEntityEffect & operator=(cEntityEffect a_OtherEffect);
+ cEntityEffect & operator =(cEntityEffect a_OtherEffect);
virtual ~cEntityEffect(void) {}
diff --git a/src/Globals.h b/src/Globals.h
index b35af9604..60ee456c9 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -156,11 +156,11 @@ template class SizeChecker;
template class SizeChecker;
template class SizeChecker;
-// A macro to disallow the copy constructor and operator= functions
+// A macro to disallow the copy constructor and operator = functions
// This should be used in the private: declarations for any class that shouldn't allow copying itself
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName &); \
- void operator=(const TypeName &)
+ void operator =(const TypeName &)
// A macro that is used to mark unused function parameters, to avoid pedantic warnings in gcc
#define UNUSED(X) (void)(X)
diff --git a/src/Matrix4.h b/src/Matrix4.h
index 081847b9f..61ea60bfd 100644
--- a/src/Matrix4.h
+++ b/src/Matrix4.h
@@ -34,6 +34,8 @@ public:
{
*this = a_Rhs;
}
+
+ // tolua_end
inline Matrix4 & operator = (const Matrix4 & a_Rhs)
{
@@ -43,6 +45,8 @@ public:
}
return *this;
}
+
+ // tolua_begin
inline T & operator [] (int a_N)
{
diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h
index 978a5b5d1..5d8aa4589 100644
--- a/src/WorldStorage/WorldStorage.h
+++ b/src/WorldStorage/WorldStorage.h
@@ -93,7 +93,7 @@ protected:
sChunkLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {}
- bool operator==(const sChunkLoad other) const
+ bool operator ==(const sChunkLoad other) const
{
return this->m_ChunkX == other.m_ChunkX &&
this->m_ChunkY == other.m_ChunkY &&
From 836de13797577289e91478ce89de65d39096f9e4 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 11:57:26 +0200
Subject: [PATCH 077/751] Added cPlayer::GetUUID().
---
src/Entities/Player.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index e3203d6d1..e26808bfc 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -417,6 +417,9 @@ public:
/** Returns wheter the player can fly or not. */
virtual bool CanFly(void) const { return m_CanFly; }
+
+ /** Returns the UUID (short format) that has been read from the client, or empty string if not available. */
+ const AString & GetUUID(void) const { return m_UUID; }
// tolua_end
From 36d19723362a4b1756c03fdc2cda7b6cace4b97b Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 12:08:00 +0200
Subject: [PATCH 078/751] ToLua driver: disabled output buffering.
---
lib/tolua++/src/bin/lua/_driver.lua | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/tolua++/src/bin/lua/_driver.lua b/lib/tolua++/src/bin/lua/_driver.lua
index 87ecd42ea..1ca18862b 100644
--- a/lib/tolua++/src/bin/lua/_driver.lua
+++ b/lib/tolua++/src/bin/lua/_driver.lua
@@ -3,6 +3,9 @@
local mobdebugfound, mobdebug = pcall(require, "mobdebug")
if mobdebugfound then mobdebug.start() end
+-- Disable buffering for stdout, so that the results appear immediately:
+io.output():setvbuf("no")
+
-- The list of valid arguments that the ToLua scripts can process:
local KnownArgs = {
['v'] = true,
From 003f18bd0f7593bddf5c6af89e3f6fc13632300d Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 12:12:28 +0200
Subject: [PATCH 079/751] Added cMojangAPI:GetUUIDFromPlayerName().
This is a simpler way to ask for a single name -> uuid conversion.
---
MCServer/Plugins/APIDump/APIDesc.lua | 1 +
src/Protocol/MojangAPI.cpp | 28 ++++++++++++++++++++++++++++
src/Protocol/MojangAPI.h | 7 +++++++
3 files changed, 36 insertions(+)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 1fa2608b3..4f8567530 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1630,6 +1630,7 @@ a_Player:OpenWindow(Window);
Functions =
{
AddPlayerNameToUUIDMapping = { Params = "PlayerName, UUID", Return = "", Notes = "Adds the specified PlayerName-to-UUID mapping into the cache, with current timestamp." },
+ GetUUIDFromPlayerName = { Params = "PlayerName, [UseOnlyCached]", Return = "UUID", Notes = "Returns the UUID that corresponds to the given playername, or an empty string on error. If UseOnlyCached is false (the default), queries the Mojang servers if the playername is not in the cache.
WARNING: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
GetUUIDsFromPlayerNames = { Params = "PlayerNames, [UseOnlyCached]", Return = "table", Notes = "Returns a table that contains the map, 'PlayerName' -> 'UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. If UseOnlyCached is false (the default), queries the Mojang servers for the results that are not in the cache.
WARNING: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
MakeUUIDDashed = { Params = "UUID", Return = "DashedUUID", Notes = "(STATIC) Converts the UUID to a dashed format (\"01234567-8901-2345-6789-012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
MakeUUIDShort = { Params = "UUID", Return = "ShortUUID", Notes = "(STATIC) Converts the UUID to a short format (without dashes, \"01234567890123456789012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 45baa5a4f..f53df1cba 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -129,6 +129,34 @@ void cMojangAPI::Start(cIniFile & a_SettingsIni)
+AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached)
+{
+ // Convert the playername to lowercase:
+ AString lcPlayerName(a_PlayerName);
+ StrToLower(lcPlayerName);
+
+ // Request the cache to populate any names not yet contained:
+ if (!a_UseOnlyCached)
+ {
+ AStringVector PlayerNames;
+ PlayerNames.push_back(lcPlayerName);
+ CacheNamesToUUIDs(PlayerNames);
+ }
+
+ // Retrieve from cache:
+ cNameToUUIDMap::const_iterator itr = m_NameToUUID.find(lcPlayerName);
+ if (itr == m_NameToUUID.end())
+ {
+ // No UUID found
+ return "";
+ }
+ return itr->second.m_PlayerName;
+}
+
+
+
+
+
AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames, bool a_UseOnlyCached)
{
// Convert all playernames to lowercase:
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index ac8995bb5..7f3ef4e39 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -45,6 +45,13 @@ public:
Note: only checks the string's length, not the actual content. */
static AString MakeUUIDDashed(const AString & a_UUID);
+ /** Converts a player name into a UUID.
+ The UUID will be empty on error.
+ If a_UseOnlyCached is true, the function only consults the cached values.
+ If a_UseOnlyCached is false and the name is not found in the cache, it is looked up online, which is a blocking
+ operation, do not use this in world-tick thread! */
+ AString GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached = false);
+
// tolua_end
/** Converts the player names into UUIDs.
From 98a13d97b3c913a7601b6c69c302f10b61851501 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 21:31:04 +0200
Subject: [PATCH 080/751] Trailing whitespace fix.
---
src/Mobs/Enderman.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 1dc73d654..0a1b6491a 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -103,7 +103,7 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cEnderman::CheckEventSeePlayer()
-{
+{
if (m_Target != NULL)
{
return;
From 21f52676f3848d58ff1e4eb511c691d4a4ed824b Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 21:32:20 +0200
Subject: [PATCH 081/751] cMojangAPI: Added UUID-to-Name lookup.
Also fixed the bindings, now all functions are static-like.
---
MCServer/Plugins/APIDump/APIDesc.lua | 17 +-
src/Bindings/ManualBindings.cpp | 98 ++++++-
src/Protocol/Authenticator.cpp | 4 +-
src/Protocol/MojangAPI.cpp | 385 ++++++++++++++++++++++++---
src/Protocol/MojangAPI.h | 97 +++++--
src/Root.h | 2 +-
6 files changed, 531 insertions(+), 72 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 4f8567530..ad3b24ca5 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1613,8 +1613,7 @@ a_Player:OpenWindow(Window);
some of these calls will wait for a response from the network, and so shouldn't be used while the
server is fully running (or at least when there are players connected) to avoid percepted lag.
- Some functions are static and do not require an instance to be called. For others, you need to get
- the singleton instance of this class using {{cRoot}}'s GetMojangAPI() function.
+ All the functions are static, call them using the cMojangAPI:Function()
convention.
Mojang uses two formats for UUIDs, short and dashed. MCServer works with short UUIDs internally, but
will convert to dashed UUIDs where needed - in the protocol login for example. The MakeUUIDShort()
@@ -1629,11 +1628,12 @@ a_Player:OpenWindow(Window);
]],
Functions =
{
- AddPlayerNameToUUIDMapping = { Params = "PlayerName, UUID", Return = "", Notes = "Adds the specified PlayerName-to-UUID mapping into the cache, with current timestamp." },
- GetUUIDFromPlayerName = { Params = "PlayerName, [UseOnlyCached]", Return = "UUID", Notes = "Returns the UUID that corresponds to the given playername, or an empty string on error. If UseOnlyCached is false (the default), queries the Mojang servers if the playername is not in the cache.
WARNING: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
- GetUUIDsFromPlayerNames = { Params = "PlayerNames, [UseOnlyCached]", Return = "table", Notes = "Returns a table that contains the map, 'PlayerName' -> 'UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. If UseOnlyCached is false (the default), queries the Mojang servers for the results that are not in the cache.
WARNING: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
- MakeUUIDDashed = { Params = "UUID", Return = "DashedUUID", Notes = "(STATIC) Converts the UUID to a dashed format (\"01234567-8901-2345-6789-012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
- MakeUUIDShort = { Params = "UUID", Return = "ShortUUID", Notes = "(STATIC) Converts the UUID to a short format (without dashes, \"01234567890123456789012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
+ AddPlayerNameToUUIDMapping = { Params = "PlayerName, UUID", Return = "", Notes = "(STATIC) Adds the specified PlayerName-to-UUID mapping into the cache, with current timestamp. Accepts both short or dashed UUIDs. " },
+ GetPlayerNameFromUUID = { Params = "UUID, [UseOnlyCached]", Return = "PlayerName", Notes = "(STATIC) Returns the playername that corresponds to the given UUID, or an empty string on error. If UseOnlyCached is false (the default), queries the Mojang servers if the UUID is not in the cache. The UUID can be either short or dashed.
WARNING: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
+ GetUUIDFromPlayerName = { Params = "PlayerName, [UseOnlyCached]", Return = "UUID", Notes = "(STATIC) Returns the (short) UUID that corresponds to the given playername, or an empty string on error. If UseOnlyCached is false (the default), queries the Mojang servers if the playername is not in the cache.
WARNING: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
+ GetUUIDsFromPlayerNames = { Params = "PlayerNames, [UseOnlyCached]", Return = "table", Notes = "(STATIC) Returns a table that contains the map, 'PlayerName' -> '(short) UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. If UseOnlyCached is false (the default), queries the Mojang servers for the results that are not in the cache.
WARNING: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
+ MakeUUIDDashed = { Params = "UUID", Return = "DashedUUID", Notes = "(STATIC) Converts the UUID to a dashed format (\"01234567-8901-2345-6789-012345678901\"). Accepts both dashed or short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
+ MakeUUIDShort = { Params = "UUID", Return = "ShortUUID", Notes = "(STATIC) Converts the UUID to a short format (without dashes, \"01234567890123456789012345678901\"). Accepts both dashed or short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
},
},
@@ -2017,7 +2017,6 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
]],
Functions =
{
- Get = { Params = "", Return = "Root object", Notes = "(STATIC)This function returns the cRoot object." },
BroadcastChat = { Params = "Message", Return = "", Notes = "Broadcasts a message to every player in the server. No formatting is done by the server." },
BroadcastChatFailure = { Params = "Message", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a command that failed to run because of insufficient permissions, etc." },
BroadcastChatFatal = { Params = "Message", Return = "", Notes = "Prepends Red [FATAL] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a plugin that crashed, or similar." },
@@ -2028,12 +2027,12 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "", Notes = "Calls the given callback function for all players with names partially (or fully) matching the name string provided." },
ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature:
function Callback({{cPlayer|cPlayer}})
" },
ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature: function Callback({{cWorld|cWorld}})
" },
+ Get = { Params = "", Return = "Root object", Notes = "(STATIC)This function returns the cRoot object." },
GetCraftingRecipes = { Params = "", Return = "{{cCraftingRecipe|cCraftingRecipe}}", Notes = "Returns the CraftingRecipes object" },
GetDefaultWorld = { Params = "", Return = "{{cWorld|cWorld}}", Notes = "Returns the world object from the default world." },
GetFurnaceFuelBurnTime = { Params = "{{cItem|Fuel}}", Return = "number", Notes = "(STATIC) Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel." },
GetFurnaceRecipe = { Params = "{{cItem|InItem}}", Return = "{{cItem|OutItem}}, NumTicks, {{cItem|InItem}}", Notes = "(STATIC) Returns the furnace recipe for smelting the specified input. If a recipe is found, returns the smelted result, the number of ticks required for the smelting operation, and the input consumed (note that MCServer supports smelting M items into N items and different smelting rates). If no recipe is found, returns no value." },
GetGroupManager = { Params = "", Return = "{{cGroupManager|cGroupManager}}", Notes = "Returns the cGroupManager object." },
- GetMojangAPI = { Params = "", Return = "{{cMojangAPI}}", Notes = "Returns the {{cMojangAPI}} object." },
GetPhysicalRAMUsage = { Params = "", Return = "number", Notes = "Returns the amount of physical RAM that the entire MCServer process is using, in KiB. Negative if the OS doesn't support this query." },
GetPluginManager = { Params = "", Return = "{{cPluginManager|cPluginManager}}", Notes = "Returns the cPluginManager object." },
GetPrimaryServerVersion = { Params = "", Return = "number", Notes = "Returns the servers primary server version." },
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 34f0d7e30..042ffb19e 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2158,6 +2158,99 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L)
+static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping(lua_State * L)
+{
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cMojangAPI") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamString(3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Retrieve the parameters:
+ AString UUID, PlayerName;
+ S.GetStackValue(2, PlayerName);
+ S.GetStackValue(3, UUID);
+
+ // Store in the cache:
+ cRoot::Get()->GetMojangAPI().AddPlayerNameToUUIDMapping(PlayerName, UUID);
+ return 0;
+}
+
+
+
+
+
+static int tolua_cMojangAPI_GetPlayerNameFromUUID(lua_State * L)
+{
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cMojangAPI") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ AString UUID;
+ S.GetStackValue(2, UUID);
+
+ // If the UseOnlyCached param was given, read it; default to false
+ bool ShouldUseCacheOnly = false;
+ if (lua_gettop(L) == 3)
+ {
+ ShouldUseCacheOnly = (lua_toboolean(L, 3) != 0);
+ lua_pop(L, 1);
+ }
+
+ // Return the PlayerName:
+ AString PlayerName = cRoot::Get()->GetMojangAPI().GetPlayerNameFromUUID(UUID, ShouldUseCacheOnly);
+ S.Push(PlayerName);
+ return 1;
+}
+
+
+
+
+
+static int tolua_cMojangAPI_GetUUIDFromPlayerName(lua_State * L)
+{
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cMojangAPI") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ AString PlayerName;
+ S.GetStackValue(2, PlayerName);
+
+ // If the UseOnlyCached param was given, read it; default to false
+ bool ShouldUseCacheOnly = false;
+ if (lua_gettop(L) == 3)
+ {
+ ShouldUseCacheOnly = (lua_toboolean(L, 3) != 0);
+ lua_pop(L, 1);
+ }
+
+ // Return the UUID:
+ AString UUID = cRoot::Get()->GetMojangAPI().GetUUIDFromPlayerName(PlayerName, ShouldUseCacheOnly);
+ S.Push(UUID);
+ return 1;
+}
+
+
+
+
+
static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
{
cLuaState S(L);
@@ -3158,7 +3251,10 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cMojangAPI");
- tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cMojangAPI_GetUUIDsFromPlayerNames);
+ tolua_function(tolua_S, "AddPlayerNameToUUIDMapping", tolua_cMojangAPI_AddPlayerNameToUUIDMapping);
+ tolua_function(tolua_S, "GetPlayerNameFromUUID", tolua_cMojangAPI_GetPlayerNameFromUUID);
+ tolua_function(tolua_S, "GetUUIDFromPlayerName", tolua_cMojangAPI_GetUUIDFromPlayerName);
+ tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cMojangAPI_GetUUIDsFromPlayerNames);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cItemGrid");
diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp
index 160564d51..984000795 100644
--- a/src/Protocol/Authenticator.cpp
+++ b/src/Protocol/Authenticator.cpp
@@ -191,8 +191,8 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
a_UUID = cMojangAPI::MakeUUIDShort(root.get("id", "").asString());
a_Properties = root["properties"];
- // Store the player's UUID in the NameToUUID map in MojangAPI:
- cRoot::Get()->GetMojangAPI().AddPlayerNameToUUIDMapping(a_UserName, a_UUID);
+ // Store the player's profile in the MojangAPI caches:
+ cRoot::Get()->GetMojangAPI().AddPlayerProfile(a_UserName, a_UUID, a_Properties);
return true;
}
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index f53df1cba..9fdf07380 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -25,8 +25,10 @@ const int MAX_PER_QUERY = 100;
-#define DEFAULT_NAME_TO_UUID_SERVER "api.mojang.com"
-#define DEFAULT_NAME_TO_UUID_ADDRESS "/profiles/minecraft"
+#define DEFAULT_NAME_TO_UUID_SERVER "api.mojang.com"
+#define DEFAULT_NAME_TO_UUID_ADDRESS "/profiles/minecraft"
+#define DEFAULT_UUID_TO_PROFILE_SERVER "sessionserver.mojang.com"
+#define DEFAULT_UUID_TO_PROFILE_ADDRESS "/session/minecraft/profile/%UUID%?unsigned=false"
@@ -96,12 +98,66 @@ static const AString & StarfieldCACert(void)
+////////////////////////////////////////////////////////////////////////////////
+// cMojangAPI::sProfile:
+
+cMojangAPI::sProfile::sProfile(
+ const AString & a_PlayerName,
+ const AString & a_UUID,
+ const Json::Value & a_Properties,
+ Int64 a_DateTime
+) :
+ m_PlayerName(a_PlayerName),
+ m_UUID(a_UUID),
+ m_Textures(),
+ m_TexturesSignature(),
+ m_DateTime(a_DateTime)
+{
+ /*
+ Example a_Profile contents:
+ "properties":
+ [
+ {
+ "name": "textures",
+ "value": "eyJ0aW1lc3RhbXAiOjE0MDcwNzAzMjEyNzEsInByb2ZpbGVJZCI6ImIxY2FmMjQyMDJhODQxYTc4MDU1YTA3OWM0NjBlZWU3IiwicHJvZmlsZU5hbWUiOiJ4b2Z0IiwiaXNQdWJsaWMiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9iNzc5YmFiZjVhNTg3Zjk0OGFkNjc0N2VhOTEyNzU0MjliNjg4Mjk1YWUzYzA3YmQwZTJmNWJmNGQwNTIifX19",
+ "signature": "XCty+jGEF39hEPrPhYNnCX087kPaoCjYruzYI/DS4nkL5hbjnkSM5Rh15hnUyv/FHhC8OF5rif3D1tQjtMI19KSVaXoUFXpbJM8/+PB8GDgEbX8Fc3u9nYkzOcM/xfxdYsFAdFhLQMkvase/BZLSuPhdy9DdI+TCrO7xuSTZfYmmwVuWo3w5gCY+mSIAnqltnOzaOOTcly75xvO0WYpVk7nJdnR2tvSi0wfrQPDrIg/uzhX7p0SnDqijmBU4QaNez/TNKiFxy69dAzt0RSotlQzqkDbyVKhhv9a4eY8h3pXi4UMftKEj4FAKczxLImkukJXuOn5NN15/Q+le0rJVBC60/xjKIVzltEsMN6qjWD0lQjey7WEL+4pGhCVuWY5KzuZjFvgqszuJTFz7lo+bcHiceldJtea8/fa02eTRObZvdLxbWC9ZfFY0IhpOVKfcLdno/ddDMNMQMi5kMrJ8MZZ/PcW1w5n7MMGWPGCla1kOaC55AL0QYSMGRVEZqgU9wXI5M7sHGZKGM4mWxkbEJYBkpI/p3GyxWgV6v33ZWlsz65TqlNrR1gCLaoFCm7Sif8NqPBZUAONHYon0roXhin/DyEanS93WV6i6FC1Wisscjq2AcvnOlgTo/5nN/1QsMbjNumuMGo37sqjRqlXoPb8zEUbAhhztYuJjEfQ2Rd8="
+ }
+ ]
+ */
+
+ // Parse the Textures and TexturesSignature from the Profile:
+ if (!a_Properties.isArray())
+ {
+ // Properties is not a valid array, bail out
+ return;
+ }
+ Json::UInt Size = a_Properties.size();
+ for (Json::UInt i = 0; i < Size; i++)
+ {
+ const Json::Value & Prop = a_Properties[i];
+ AString PropName = Prop.get("name", "").asString();
+ if (PropName != "textures")
+ {
+ continue;
+ }
+ m_Textures = Prop.get("value", "").asString();
+ m_TexturesSignature = Prop.get("signature", "").asString();
+ break;
+ } // for i - Properties[]
+}
+
+
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cMojangAPI:
cMojangAPI::cMojangAPI(void) :
m_NameToUUIDServer(DEFAULT_NAME_TO_UUID_SERVER),
- m_NameToUUIDAddress(DEFAULT_NAME_TO_UUID_ADDRESS)
+ m_NameToUUIDAddress(DEFAULT_NAME_TO_UUID_ADDRESS),
+ m_UUIDToProfileServer(DEFAULT_UUID_TO_PROFILE_SERVER),
+ m_UUIDToProfileAddress(DEFAULT_UUID_TO_PROFILE_ADDRESS)
{
}
@@ -120,8 +176,10 @@ cMojangAPI::~cMojangAPI()
void cMojangAPI::Start(cIniFile & a_SettingsIni)
{
- m_NameToUUIDServer = a_SettingsIni.GetValueSet("MojangAPI", "NameToUUIDServer", DEFAULT_NAME_TO_UUID_SERVER);
- m_NameToUUIDAddress = a_SettingsIni.GetValueSet("MojangAPI", "NameToUUIDAddress", DEFAULT_NAME_TO_UUID_ADDRESS);
+ m_NameToUUIDServer = a_SettingsIni.GetValueSet("MojangAPI", "NameToUUIDServer", DEFAULT_NAME_TO_UUID_SERVER);
+ m_NameToUUIDAddress = a_SettingsIni.GetValueSet("MojangAPI", "NameToUUIDAddress", DEFAULT_NAME_TO_UUID_ADDRESS);
+ m_UUIDToProfileServer = a_SettingsIni.GetValueSet("MojangAPI", "UUIDToProfileServer", DEFAULT_UUID_TO_PROFILE_SERVER);
+ m_UUIDToProfileAddress = a_SettingsIni.GetValueSet("MojangAPI", "UUIDToProfileAddress", DEFAULT_UUID_TO_PROFILE_ADDRESS);
LoadCachesFromDisk();
}
@@ -135,7 +193,7 @@ AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_U
AString lcPlayerName(a_PlayerName);
StrToLower(lcPlayerName);
- // Request the cache to populate any names not yet contained:
+ // Request the cache to query the name if not yet cached:
if (!a_UseOnlyCached)
{
AStringVector PlayerNames;
@@ -144,7 +202,8 @@ AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_U
}
// Retrieve from cache:
- cNameToUUIDMap::const_iterator itr = m_NameToUUID.find(lcPlayerName);
+ cCSLock Lock(m_CSNameToUUID);
+ cProfileMap::const_iterator itr = m_NameToUUID.find(lcPlayerName);
if (itr == m_NameToUUID.end())
{
// No UUID found
@@ -157,6 +216,44 @@ AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_U
+AString cMojangAPI::GetPlayerNameFromUUID(const AString & a_UUID, bool a_UseOnlyCached)
+{
+ // Normalize the UUID to lowercase short format that is used as the map key:
+ AString UUID = StrToLower(MakeUUIDShort(a_UUID));
+
+ // Retrieve from caches:
+ {
+ cCSLock Lock(m_CSUUIDToProfile);
+ cProfileMap::const_iterator itr = m_UUIDToProfile.find(UUID);
+ if (itr != m_UUIDToProfile.end())
+ {
+ return itr->second.m_PlayerName;
+ }
+ }
+ {
+ cCSLock Lock(m_CSUUIDToName);
+ cProfileMap::const_iterator itr = m_UUIDToName.find(UUID);
+ if (itr != m_UUIDToName.end())
+ {
+ return itr->second.m_PlayerName;
+ }
+ }
+
+ // Name not yet cached, request cache and retry:
+ if (!a_UseOnlyCached)
+ {
+ CacheUUIDToProfile(UUID);
+ return GetPlayerNameFromUUID(a_UUID, true);
+ }
+
+ // No value found, none queried. Return an error:
+ return "";
+}
+
+
+
+
+
AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames, bool a_UseOnlyCached)
{
// Convert all playernames to lowercase:
@@ -180,7 +277,7 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player
cCSLock Lock(m_CSNameToUUID);
for (AStringVector::const_iterator itr = PlayerNames.begin(), end = PlayerNames.end(); itr != end; ++itr, ++idx)
{
- cNameToUUIDMap::const_iterator itrN = m_NameToUUID.find(*itr);
+ cProfileMap::const_iterator itrN = m_NameToUUID.find(*itr);
if (itrN != m_NameToUUID.end())
{
res[idx] = itrN->second.m_UUID;
@@ -196,10 +293,39 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player
void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID)
{
AString lcName(a_PlayerName);
- AString UUID = MakeUUIDShort(a_UUID);
+ AString UUID = StrToLower(MakeUUIDShort(a_UUID));
Int64 Now = time(NULL);
- cCSLock Lock(m_CSNameToUUID);
- m_NameToUUID[StrToLower(lcName)] = sUUIDRecord(a_PlayerName, UUID, Now);
+ {
+ cCSLock Lock(m_CSNameToUUID);
+ m_NameToUUID[StrToLower(lcName)] = sProfile(a_PlayerName, UUID, "", "", Now);
+ }
+ {
+ cCSLock Lock(m_CSUUIDToName);
+ m_UUIDToName[UUID] = sProfile(a_PlayerName, UUID, "", "", Now);
+ }
+}
+
+
+
+
+
+void cMojangAPI::AddPlayerProfile(const AString & a_PlayerName, const AString & a_UUID, const Json::Value & a_Properties)
+{
+ AString lcName(a_PlayerName);
+ AString UUID = StrToLower(MakeUUIDShort(a_UUID));
+ Int64 Now = time(NULL);
+ {
+ cCSLock Lock(m_CSNameToUUID);
+ m_NameToUUID[StrToLower(lcName)] = sProfile(a_PlayerName, UUID, "", "", Now);
+ }
+ {
+ cCSLock Lock(m_CSUUIDToName);
+ m_UUIDToName[UUID] = sProfile(a_PlayerName, UUID, "", "", Now);
+ }
+ {
+ cCSLock Lock(m_CSUUIDToProfile);
+ m_UUIDToProfile[UUID] = sProfile(a_PlayerName, UUID, a_Properties, Now);
+ }
}
@@ -337,6 +463,7 @@ void cMojangAPI::LoadCachesFromDisk(void)
// Open up the SQLite DB:
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)");
// Clean up old entries:
{
@@ -345,16 +472,40 @@ void cMojangAPI::LoadCachesFromDisk(void)
stmt.bind(1, LimitDateTime);
stmt.exec();
}
-
- // Retrieve all remaining entries::
- SQLite::Statement stmt(db, "SELECT PlayerName, UUID, DateTime FROM PlayerNameToUUID");
- while (stmt.executeStep())
{
- AString PlayerName = stmt.getColumn(0);
- AString UUID = stmt.getColumn(1);
- Int64 DateTime = stmt.getColumn(2);
- AString lcPlayerName = PlayerName;
- m_NameToUUID[StrToLower(lcPlayerName)] = sUUIDRecord(PlayerName, UUID, DateTime);
+ SQLite::Statement stmt(db, "DELETE FROM UUIDToProfile WHERE DateTime < ?");
+ Int64 LimitDateTime = time(NULL) - MAX_AGE;
+ stmt.bind(1, LimitDateTime);
+ stmt.exec();
+ }
+
+ // Retrieve all remaining entries:
+ {
+ SQLite::Statement stmt(db, "SELECT PlayerName, UUID, DateTime FROM PlayerNameToUUID");
+ while (stmt.executeStep())
+ {
+ AString PlayerName = stmt.getColumn(0);
+ AString UUID = stmt.getColumn(1);
+ Int64 DateTime = stmt.getColumn(2);
+ AString lcPlayerName = PlayerName;
+ UUID = StrToLower(MakeUUIDShort(UUID));
+ m_NameToUUID[StrToLower(lcPlayerName)] = sProfile(PlayerName, UUID, "", "", DateTime);
+ m_UUIDToName[UUID] = sProfile(PlayerName, UUID, "", "", DateTime);
+ }
+ }
+ {
+ SQLite::Statement stmt(db, "SELECT PlayerName, UUID, Textures, TexturesSignature, DateTime FROM UUIDToProfile");
+ while (stmt.executeStep())
+ {
+ AString PlayerName = stmt.getColumn(0);
+ AString UUID = stmt.getColumn(1);
+ AString Textures = stmt.getColumn(2);
+ AString TexturesSignature = stmt.getColumn(2);
+ Int64 DateTime = stmt.getColumn(4);
+ AString lcPlayerName = PlayerName;
+ UUID = StrToLower(MakeUUIDShort(UUID));
+ m_UUIDToProfile[StrToLower(lcPlayerName)] = sProfile(PlayerName, UUID, Textures, TexturesSignature, DateTime);
+ }
}
}
catch (const SQLite::Exception & ex)
@@ -374,26 +525,51 @@ void cMojangAPI::SaveCachesToDisk(void)
// Open up the SQLite DB:
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:
- SQLite::Statement stmt(db, "INSERT INTO PlayerNameToUUID(PlayerName, UUID, DateTime) VALUES (?, ?, ?)");
+ // Save all cache entries - m_PlayerNameToUUID:
Int64 LimitDateTime = time(NULL) - MAX_AGE;
- cCSLock Lock(m_CSNameToUUID);
- for (cNameToUUIDMap::const_iterator itr = m_NameToUUID.begin(), end = m_NameToUUID.end(); itr != end; ++itr)
{
- if (itr->second.m_DateTime < LimitDateTime)
+ SQLite::Statement stmt(db, "INSERT INTO PlayerNameToUUID(PlayerName, UUID, DateTime) VALUES (?, ?, ?)");
+ cCSLock Lock(m_CSNameToUUID);
+ for (cProfileMap::const_iterator itr = m_NameToUUID.begin(), end = m_NameToUUID.end(); itr != end; ++itr)
{
- // This item is too old, do not save
- continue;
+ if (itr->second.m_DateTime < LimitDateTime)
+ {
+ // This item is too old, do not save
+ continue;
+ }
+ stmt.bind(1, itr->second.m_PlayerName);
+ stmt.bind(2, itr->second.m_UUID);
+ stmt.bind(3, itr->second.m_DateTime);
+ stmt.exec();
+ stmt.reset();
+ }
+ }
+
+ // Save all cache entries - m_UUIDToProfile:
+ {
+ SQLite::Statement stmt(db, "INSERT INTO UUIDToProfile(UUID, PlayerName, Textures, TexturesSignature, DateTime) VALUES (?, ?, ?, ?, ?)");
+ cCSLock Lock(m_CSUUIDToProfile);
+ for (cProfileMap::const_iterator itr = m_UUIDToProfile.begin(), end = m_UUIDToProfile.end(); itr != end; ++itr)
+ {
+ if (itr->second.m_DateTime < LimitDateTime)
+ {
+ // This item is too old, do not save
+ continue;
+ }
+ stmt.bind(1, itr->second.m_UUID);
+ stmt.bind(2, itr->second.m_PlayerName);
+ stmt.bind(3, itr->second.m_Textures);
+ stmt.bind(4, itr->second.m_TexturesSignature);
+ stmt.bind(5, itr->second.m_DateTime);
+ stmt.exec();
+ stmt.reset();
}
- stmt.bind(1, itr->second.m_PlayerName);
- stmt.bind(2, itr->second.m_UUID);
- stmt.bind(3, itr->second.m_DateTime);
- stmt.exec();
- stmt.reset();
}
}
catch (const SQLite::Exception & ex)
@@ -487,22 +663,145 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
// Store the returned results into cache:
size_t JsonCount = root.size();
Int64 Now = time(NULL);
- cCSLock Lock(m_CSNameToUUID);
- for (size_t idx = 0; idx < JsonCount; ++idx)
{
- Json::Value & Val = root[idx];
- AString JsonName = Val.get("name", "").asString();
- AString JsonUUID = MakeUUIDShort(Val.get("id", "").asString());
- if (JsonUUID.empty())
+ cCSLock Lock(m_CSNameToUUID);
+ for (size_t idx = 0; idx < JsonCount; ++idx)
{
- continue;
- }
- AString lcName = JsonName;
- m_NameToUUID[StrToLower(lcName)] = sUUIDRecord(JsonName, JsonUUID, Now);
- } // for idx - root[]
+ Json::Value & Val = root[idx];
+ AString JsonName = Val.get("name", "").asString();
+ AString JsonUUID = StrToLower(MakeUUIDShort(Val.get("id", "").asString()));
+ if (JsonUUID.empty())
+ {
+ continue;
+ }
+ AString lcName = JsonName;
+ m_NameToUUID[StrToLower(lcName)] = sProfile(JsonName, JsonUUID, "", "", Now);
+ } // for idx - root[]
+ } // cCSLock (m_CSNameToUUID)
+
+ // Also cache the UUIDToName:
+ {
+ cCSLock Lock(m_CSUUIDToName);
+ for (size_t idx = 0; idx < JsonCount; ++idx)
+ {
+ Json::Value & Val = root[idx];
+ AString JsonName = Val.get("name", "").asString();
+ AString JsonUUID = StrToLower(MakeUUIDShort(Val.get("id", "").asString()));
+ if (JsonUUID.empty())
+ {
+ continue;
+ }
+ m_UUIDToName[JsonUUID] = sProfile(JsonName, JsonUUID, "", "", Now);
+ } // for idx - root[]
+ }
} // while (!NamesToQuery.empty())
}
+
+void cMojangAPI::CacheUUIDToProfile(const AString & a_UUID)
+{
+ ASSERT(a_UUID.size() == 32);
+
+ // Check if already present:
+ {
+ if (m_UUIDToProfile.find(a_UUID) != m_UUIDToProfile.end())
+ {
+ return;
+ }
+ }
+
+ // 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
+ Request += "Host: " + m_UUIDToProfileServer + "\r\n";
+ Request += "User-Agent: MCServer\r\n";
+ Request += "Connection: close\r\n";
+ Request += "Content-Length: 0\r\n";
+ Request += "\r\n";
+
+ // Get the response from the server:
+ AString Response;
+ if (!SecureRequest(m_UUIDToProfileServer, Request, Response))
+ {
+ return;
+ }
+
+ // Check the HTTP status line:
+ const AString Prefix("HTTP/1.1 200 OK");
+ AString HexDump;
+ if (Response.compare(0, Prefix.size(), Prefix))
+ {
+ LOGINFO("%s failed: bad HTTP status line received", __FUNCTION__);
+ LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ return;
+ }
+
+ // Erase the HTTP headers from the response:
+ size_t idxHeadersEnd = Response.find("\r\n\r\n");
+ if (idxHeadersEnd == AString::npos)
+ {
+ LOGINFO("%s failed: bad HTTP response header received", __FUNCTION__);
+ LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ return;
+ }
+ Response.erase(0, idxHeadersEnd + 4);
+
+ // Parse the returned string into Json:
+ Json::Reader reader;
+ Json::Value root;
+ if (!reader.parse(Response, root, false) || !root.isObject())
+ {
+ LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON!", __FUNCTION__);
+ LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
+ return;
+ }
+
+ /* Example response:
+ {
+ "id": "b1caf24202a841a78055a079c460eee7",
+ "name": "xoft",
+ "properties":
+ [
+ {
+ "name": "textures",
+ "value": "eyJ0aW1lc3RhbXAiOjE0MDcwNzAzMjEyNzEsInByb2ZpbGVJZCI6ImIxY2FmMjQyMDJhODQxYTc4MDU1YTA3OWM0NjBlZWU3IiwicHJvZmlsZU5hbWUiOiJ4b2Z0IiwiaXNQdWJsaWMiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9iNzc5YmFiZjVhNTg3Zjk0OGFkNjc0N2VhOTEyNzU0MjliNjg4Mjk1YWUzYzA3YmQwZTJmNWJmNGQwNTIifX19",
+ "signature": "XCty+jGEF39hEPrPhYNnCX087kPaoCjYruzYI/DS4nkL5hbjnkSM5Rh15hnUyv/FHhC8OF5rif3D1tQjtMI19KSVaXoUFXpbJM8/+PB8GDgEbX8Fc3u9nYkzOcM/xfxdYsFAdFhLQMkvase/BZLSuPhdy9DdI+TCrO7xuSTZfYmmwVuWo3w5gCY+mSIAnqltnOzaOOTcly75xvO0WYpVk7nJdnR2tvSi0wfrQPDrIg/uzhX7p0SnDqijmBU4QaNez/TNKiFxy69dAzt0RSotlQzqkDbyVKhhv9a4eY8h3pXi4UMftKEj4FAKczxLImkukJXuOn5NN15/Q+le0rJVBC60/xjKIVzltEsMN6qjWD0lQjey7WEL+4pGhCVuWY5KzuZjFvgqszuJTFz7lo+bcHiceldJtea8/fa02eTRObZvdLxbWC9ZfFY0IhpOVKfcLdno/ddDMNMQMi5kMrJ8MZZ/PcW1w5n7MMGWPGCla1kOaC55AL0QYSMGRVEZqgU9wXI5M7sHGZKGM4mWxkbEJYBkpI/p3GyxWgV6v33ZWlsz65TqlNrR1gCLaoFCm7Sif8NqPBZUAONHYon0roXhin/DyEanS93WV6i6FC1Wisscjq2AcvnOlgTo/5nN/1QsMbjNumuMGo37sqjRqlXoPb8zEUbAhhztYuJjEfQ2Rd8="
+ }
+ ]
+ }
+ */
+
+ // Store the returned result into caches:
+ AString PlayerName = root.get("name", "").asString();
+ if (PlayerName.empty())
+ {
+ // No valid playername, bail out
+ return;
+ }
+ Json::Value Properties = root.get("properties", "");
+ Int64 Now = time(NULL);
+ {
+ cCSLock Lock(m_CSUUIDToProfile);
+ m_UUIDToProfile[a_UUID] = sProfile(PlayerName, a_UUID, Properties, Now);
+ }
+ {
+ cCSLock Lock(m_CSUUIDToName);
+ m_UUIDToName[a_UUID] = sProfile(PlayerName, a_UUID, Properties, Now);
+ }
+ {
+ AString lcPlayerName(PlayerName);
+ cCSLock Lock(m_CSNameToUUID);
+ m_NameToUUID[StrToLower(lcPlayerName)] = sProfile(PlayerName, a_UUID, Properties, Now);
+ }
+}
+
+
+
+
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index 7f3ef4e39..08e799c73 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -11,6 +11,11 @@
#include
+namespace Json
+{
+ class Value;
+}
+
@@ -45,14 +50,24 @@ public:
Note: only checks the string's length, not the actual content. */
static AString MakeUUIDDashed(const AString & a_UUID);
+ // tolua_end
+
/** Converts a player name into a UUID.
The UUID will be empty on error.
If a_UseOnlyCached is true, the function only consults the cached values.
If a_UseOnlyCached is false and the name is not found in the cache, it is looked up online, which is a blocking
- operation, do not use this in world-tick thread! */
+ operation, do not use this in world-tick thread!
+ If you have multiple names to resolve, use the GetUUIDsFromPlayerNames() function, it uses a single request for multiple names. */
AString GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached = false);
- // tolua_end
+ /** Converts a UUID into a playername.
+ The returned playername will be empty on error.
+ Both short and dashed UUID formats are accepted.
+ Uses both m_UUIDToName and m_UUIDToProfile to search for the value. Uses m_UUIDToProfile for cache.
+ If a_UseOnlyCached is true, the function only consults the cached values.
+ If a_UseOnlyCached is false and the name is not found in the cache, it is looked up online, which is a blocking
+ operation, do not use this in world-tick thread! */
+ AString GetPlayerNameFromUUID(const AString & a_UUID, bool a_UseOnlyCached = false);
/** Converts the player names into UUIDs.
a_PlayerName[idx] will be converted to UUID and returned as idx-th value
@@ -62,36 +77,61 @@ public:
operation, do not use this in world-tick thread! */
AStringVector GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName, bool a_UseOnlyCached = false);
- // tolua_begin
-
/** Called by the Authenticator to add a PlayerName -> UUID mapping that it has received from
authenticating a user. This adds the cache item and "refreshes" it if existing, adjusting its datetime
stamp to now. */
void AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID);
- // tolua_end
-
+ /** Called by the Authenticator to add a profile that it has received from authenticating a user. Adds
+ the profile to the respective mapping caches and updtes their datetime stamp to now. */
+ void AddPlayerProfile(const AString & a_PlayerName, const AString & a_UUID, const Json::Value & a_Properties);
+
protected:
- struct sUUIDRecord
+ /** Holds data for a single player profile. */
+ struct sProfile
{
- AString m_PlayerName; // Case-correct playername
- AString m_UUID;
- Int64 m_DateTime; // UNIXtime of the UUID lookup
+ AString m_PlayerName; // Case-correct playername
+ AString m_UUID; // Short lowercased UUID
+ AString m_Textures; // The Textures field of the profile properties
+ AString m_TexturesSignature; // The signature of the Textures field of the profile properties
+ Int64 m_DateTime; // UNIXtime of the profile lookup
- sUUIDRecord(void) :
+ /** Default constructor for the container's sake. */
+ sProfile(void) :
+ m_PlayerName(),
m_UUID(),
+ m_Textures(),
+ m_TexturesSignature(),
m_DateTime(time(NULL))
{
}
- sUUIDRecord(const AString & a_PlayerName, const AString & a_UUID, Int64 a_DateTime) :
+ /** Constructor for the storage creation. */
+ sProfile(
+ const AString & a_PlayerName,
+ const AString & a_UUID,
+ const AString & a_Textures,
+ const AString & a_TexturesSignature,
+ Int64 a_DateTime
+ ) :
m_PlayerName(a_PlayerName),
m_UUID(a_UUID),
+ m_Textures(a_Textures),
+ m_TexturesSignature(a_TexturesSignature),
m_DateTime(a_DateTime)
{
}
+
+ /** Constructor that parses the values from the Json profile. */
+ sProfile(
+ const AString & a_PlayerName,
+ const AString & a_UUID,
+ const Json::Value & a_Properties,
+ Int64 a_DateTime
+ );
};
- typedef std::map cNameToUUIDMap; // maps Lowercased PlayerName to sUUIDRecord
+ typedef std::map cProfileMap;
+
/** The server to connect to when converting player names to UUIDs. For example "api.mojang.com". */
AString m_NameToUUIDServer;
@@ -100,12 +140,32 @@ protected:
For example "/profiles/page/1". */
AString m_NameToUUIDAddress;
- /** Cache for the Name-to-UUID lookups. The map key is expected lowercased. Protected by m_CSNameToUUID. */
- cNameToUUIDMap m_NameToUUID;
+ /** The server to connect to when converting UUID to profile. For example "sessionserver.mojang.com". */
+ AString m_UUIDToProfileServer;
+
+ /** The URL to use for converting UUID to profile, without the server part.
+ Will replace %UUID% with the actual UUID. For example "session/minecraft/profile/%UUID%?unsigned=false". */
+ AString m_UUIDToProfileAddress;
+
+ /** Cache for the Name-to-UUID lookups. The map key is lowercased PlayerName. Protected by m_CSNameToUUID. */
+ cProfileMap m_NameToUUID;
/** Protects m_NameToUUID against simultaneous multi-threaded access. */
cCriticalSection m_CSNameToUUID;
+ /** Cache for the Name-to-UUID lookups. The map key is lowercased short UUID. Protected by m_CSUUIDToName. */
+ cProfileMap m_UUIDToName;
+
+ /** Protects m_UUIDToName against simultaneous multi-threaded access. */
+ cCriticalSection m_CSUUIDToName;
+
+ /** Cache for the UUID-to-profile lookups. The map key is lowercased short UUID.
+ Protected by m_CSUUIDToProfile. */
+ cProfileMap m_UUIDToProfile;
+
+ /** Protects m_UUIDToProfile against simultaneous multi-threaded access. */
+ cCriticalSection m_CSUUIDToProfile;
+
/** Loads the caches from a disk storage. */
void LoadCachesFromDisk(void);
@@ -113,10 +173,15 @@ protected:
/** Saves the caches to a disk storage. */
void SaveCachesToDisk(void);
- /** Makes sure all specified names are in the cache. Downloads any missing ones from Mojang API servers.
+ /** Makes sure all specified names are in the m_PlayerNameToUUID cache. Downloads any missing ones from Mojang API servers.
Names that are not valid are not added into the cache.
ASSUMEs that a_PlayerNames contains lowercased player names. */
void CacheNamesToUUIDs(const AStringVector & a_PlayerNames);
+
+ /** Makes sure the specified UUID is in the m_UUIDToProfile cache. If missing, downloads it from Mojang API servers.
+ UUIDs that are not valid will not be added into the cache.
+ ASSUMEs that a_UUID is a lowercased short UUID. */
+ void CacheUUIDToProfile(const AString & a_UUID);
} ; // tolua_export
diff --git a/src/Root.h b/src/Root.h
index 5cb82edda..1cd175ab4 100644
--- a/src/Root.h
+++ b/src/Root.h
@@ -88,7 +88,7 @@ public:
cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export
cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
- cMojangAPI & GetMojangAPI (void) { return m_MojangAPI; } // tolua_export
+ cMojangAPI & GetMojangAPI (void) { return m_MojangAPI; }
/** Queues a console command for execution through the cServer class.
The command will be executed in the tick thread
From f5aaf52210369862a045c074429428012607c445 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 21:32:53 +0200
Subject: [PATCH 082/751] Debuggers: Added a Name-from-UUID cMojangAPI test.
---
MCServer/Plugins/Debuggers/Debuggers.lua | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 075cfa40c..7e220952e 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -339,6 +339,13 @@ function TestUUIDFromName()
end
LOG("UUID-from-Name resolution tests finished.")
+
+ LOG("Performing a Name-from-UUID test...")
+ -- local NameToTest = "aloe_vera"
+ local NameToTest = "xoft"
+ local Name = cMojangAPI:GetPlayerNameFromUUID(UUIDs[NameToTest])
+ LOG("Name(" .. UUIDs[NameToTest] .. ") = '" .. Name .. "', expected '" .. NameToTest .. "'.")
+ LOG("Name-from-UUID test finished.")
end
From 3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 22:03:48 +0200
Subject: [PATCH 083/751] Wolf uses UUID for owner.
Fixes #1277.
---
src/Mobs/Wolf.cpp | 6 ++-
src/Mobs/Wolf.h | 10 +++-
src/WorldStorage/NBTChunkSerializer.cpp | 10 ++--
src/WorldStorage/WSSAnvil.cpp | 69 +++++++++++++++++++++----
src/WorldStorage/WSSAnvil.h | 4 ++
5 files changed, 82 insertions(+), 17 deletions(-)
diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp
index 5bb97d30e..4fe1ff1d6 100644
--- a/src/Mobs/Wolf.cpp
+++ b/src/Mobs/Wolf.cpp
@@ -68,6 +68,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
{
if (!IsTame() && !IsAngry())
{
+ // If the player is holding a bone, try to tame the wolf:
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE)
{
if (!a_Player.IsGameModeCreative())
@@ -77,14 +78,16 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
if (m_World->GetTickRandomNumber(7) == 0)
{
+ // Taming succeeded
SetMaxHealth(20);
SetIsTame(true);
- SetOwner(a_Player.GetName());
+ SetOwner(a_Player.GetName(), a_Player.GetUUID());
m_World->BroadcastEntityStatus(*this, esWolfTamed);
m_World->BroadcastParticleEffect("heart", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5);
}
else
{
+ // Taming failed
m_World->BroadcastEntityStatus(*this, esWolfTaming);
m_World->BroadcastParticleEffect("smoke", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5);
}
@@ -92,6 +95,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
}
else if (IsTame())
{
+ // Feed the wolf, restoring its health, or dye its collar:
switch (a_Player.GetEquippedItem().m_ItemType)
{
case E_ITEM_RAW_BEEF:
diff --git a/src/Mobs/Wolf.h b/src/Mobs/Wolf.h
index 2e83db701..7500854f8 100644
--- a/src/Mobs/Wolf.h
+++ b/src/Mobs/Wolf.h
@@ -29,7 +29,8 @@ public:
bool IsTame (void) const { return m_IsTame; }
bool IsBegging (void) const { return m_IsBegging; }
bool IsAngry (void) const { return m_IsAngry; }
- AString GetOwner (void) const { return m_OwnerName; }
+ AString GetOwnerName (void) const { return m_OwnerName; }
+ AString GetOwnerUUID (void) const { return m_OwnerUUID; }
int GetCollarColor(void) const { return m_CollarColor; }
// Set functions
@@ -37,8 +38,12 @@ public:
void SetIsTame (bool a_IsTame) { m_IsTame = a_IsTame; }
void SetIsBegging (bool a_IsBegging) { m_IsBegging = a_IsBegging; }
void SetIsAngry (bool a_IsAngry) { m_IsAngry = a_IsAngry; }
- void SetOwner (const AString & a_NewOwner) { m_OwnerName = a_NewOwner; }
void SetCollarColor(int a_CollarColor) { m_CollarColor = a_CollarColor; }
+ void SetOwner (const AString & a_NewOwnerName, const AString & a_NewOwnerUUID)
+ {
+ m_OwnerName = a_NewOwnerName;
+ m_OwnerUUID = a_NewOwnerUUID;
+ }
protected:
@@ -47,6 +52,7 @@ protected:
bool m_IsBegging;
bool m_IsAngry;
AString m_OwnerName;
+ AString m_OwnerUUID;
int m_CollarColor;
} ;
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 601cd8833..ecda9b8fd 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -569,10 +569,12 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
}
case cMonster::mtWolf:
{
- m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner());
- m_Writer.AddByte("Sitting", (((const cWolf *)a_Monster)->IsSitting() ? 1 : 0));
- m_Writer.AddByte("Angry", (((const cWolf *)a_Monster)->IsAngry() ? 1 : 0));
- m_Writer.AddInt("CollarColor", ((const cWolf *)a_Monster)->GetCollarColor());
+ const cWolf & Wolf = *((cWolf *)a_Monster);
+ m_Writer.AddString("Owner", Wolf.GetOwnerName());
+ m_Writer.AddString("OwnerUUID", Wolf.GetOwnerUUID());
+ m_Writer.AddByte("Sitting", Wolf.IsSitting() ? 1 : 0);
+ m_Writer.AddByte("Angry", Wolf.IsAngry() ? 1 : 0);
+ m_Writer.AddInt("CollarColor", Wolf.GetCollarColor());
break;
}
case cMonster::mtZombie:
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index d3a156ee1..434f1e21f 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -15,6 +15,7 @@
#include "../ItemGrid.h"
#include "../StringCompression.h"
#include "../SetChunkData.h"
+#include "../Root.h"
#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
@@ -49,6 +50,8 @@
#include "../Entities/HangingEntity.h"
#include "../Entities/ItemFrame.h"
+#include "../Protocol/MojangAPI.h"
+
@@ -2411,16 +2414,9 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
{
return;
}
- int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
- if (OwnerIdx > 0)
- {
- AString OwnerName = a_NBT.GetString(OwnerIdx);
- if (OwnerName != "")
- {
- Monster->SetOwner(OwnerName);
- Monster->SetIsTame(true);
- }
- }
+
+ LoadWolfOwner(*Monster.get(), a_NBT, a_TagIdx);
+
int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting");
if (SittingIdx > 0)
{
@@ -2492,6 +2488,59 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
+void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ // Load the owner information. OwnerUUID or Owner may be specified, possibly both:
+ AString OwnerUUID, OwnerName;
+ int OwnerUUIDIdx = a_NBT.FindChildByName(a_TagIdx, "OwnerUUID");
+ if (OwnerUUIDIdx > 0)
+ {
+ OwnerUUID = cMojangAPI::MakeUUIDShort(a_NBT.GetString(OwnerUUIDIdx));
+ }
+ int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
+ if (OwnerIdx > 0)
+ {
+ OwnerName = a_NBT.GetString(OwnerIdx);
+ }
+ if (OwnerName.empty() && OwnerUUID.empty())
+ {
+ // There is no owner, bail out:
+ return;
+ }
+
+ // Convert name to UUID, if needed:
+ if (OwnerUUID.empty())
+ {
+ // This wolf has only playername stored (pre-1.7.6), look up the UUID
+ // The lookup is blocking, but we're running in a separate thread, so it's ok
+ OwnerUUID = cRoot::Get()->GetMojangAPI().GetUUIDFromPlayerName(OwnerName);
+ if (OwnerUUID.empty())
+ {
+ // Not a known player, un-tame the wolf by bailing out
+ return;
+ }
+ }
+
+ // Convert UUID to name, if needed:
+ if (OwnerName.empty())
+ {
+ // The lookup is blocking, but we're running in a separate thread, so it's ok
+ OwnerName = cRoot::Get()->GetMojangAPI().GetPlayerNameFromUUID(OwnerUUID);
+ if (OwnerName.empty())
+ {
+ // Not a known player, un-tame the wolf by bailing out
+ return;
+ }
+ }
+
+ a_Wolf.SetOwner(OwnerName, OwnerUUID);
+ a_Wolf.SetIsTame(true);
+}
+
+
+
+
+
bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx)
{
double Pos[3];
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index f8eeb8247..a41268f4c 100644
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -21,6 +21,7 @@ class cItemGrid;
class cProjectileEntity;
class cHangingEntity;
+class cWolf;
@@ -201,6 +202,9 @@ protected:
void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
+ /** Loads the wolf's owner information from the NBT into the specified wolf entity. */
+ void LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_TagIdx);
+
/// Loads entity common data from the NBT compound; returns true if successful
bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx);
From 977a9948b9ed52d0dd8c4695ecfca981b06bb212 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 3 Aug 2014 22:15:26 +0200
Subject: [PATCH 084/751] Fixed skins in mc 1.7.9/1.7.10
---
src/Protocol/Protocol17x.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index f419c01a7..d6f4b96dc 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -3032,15 +3032,14 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player)
Pkt.WriteString(cMojangAPI::MakeUUIDDashed(a_Player.GetClientHandle()->GetUUID()));
Pkt.WriteString(a_Player.GetName());
- const Json::Value & Properties = m_Client->GetProperties();
- const Json::Value::const_iterator End = Properties.end();
+ const Json::Value & Properties = a_Player.GetClientHandle()->GetProperties();
Pkt.WriteVarInt(Properties.size());
- for (Json::Value::iterator itr = Properties.begin(); itr != End; ++itr)
+ for (Json::Value::iterator itr = Properties.begin(); itr != Properties.end(); ++itr)
{
- Pkt.WriteString(((Json::Value)*itr).get("name", "").toStyledString());
- Pkt.WriteString(((Json::Value)*itr).get("value", "").toStyledString());
- Pkt.WriteString(((Json::Value)*itr).get("signature", "").toStyledString());
+ Pkt.WriteString(((Json::Value)*itr).get("name", "").asString());
+ Pkt.WriteString(((Json::Value)*itr).get("value", "").asString());
+ Pkt.WriteString(((Json::Value)*itr).get("signature", "").asString());
}
Pkt.WriteFPInt(a_Player.GetPosX());
From b19874e6f2c8894648c25efb0e9fa176b6688729 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 3 Aug 2014 22:19:43 +0200
Subject: [PATCH 085/751] Attempting a compilation fix for gcc / clang.
---
src/StringUtils.cpp | 15 +++++++++++++++
src/StringUtils.h | 3 +++
2 files changed, 18 insertions(+)
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index b0e5a4ffe..decce8065 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -230,6 +230,21 @@ AString & StrToLower(AString & s)
+AString StrToLower(const AString & s)
+{
+ AString res;
+ res.resize(s.size());
+ for (AString::iterator itr = res.begin(), end = res.end(); itr != end; ++itr)
+ {
+ *itr = (char)tolower(*itr);
+ }
+ return res;
+}
+
+
+
+
+
int NoCaseCompare(const AString & s1, const AString & s2)
{
#ifdef _MSC_VER
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 30b9904d1..65363382d 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -48,6 +48,9 @@ extern AString & StrToUpper(AString & s);
/// In-place string conversion to lowercase; returns the same string
extern AString & StrToLower(AString & s);
+/** Returns a lower-cased copy of the string */
+extern AString StrToLower(const AString & s);
+
/// Case-insensitive string comparison; returns 0 if the strings are the same
extern int NoCaseCompare(const AString & s1, const AString & s2); // tolua_export
From 0911072d27820bd608bb908088419d3ec5151434 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 4 Aug 2014 01:34:12 +0200
Subject: [PATCH 086/751] Attempt to fix knockback and swimming.
---
src/Entities/Entity.cpp | 28 +++++++++++++---------------
src/Mobs/Monster.cpp | 12 +++++++++---
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index a274e6780..32f220897 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -244,9 +244,9 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R
Vector3d Heading(0, 0, 0);
if (a_Attacker != NULL)
{
- Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 10 : 8);
+ Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 16 : 11);
+ Heading.y = 1.6;
}
- Heading.y = 2;
TDI.Knockback = Heading * a_KnockbackAmount;
DoTakeDamage(TDI);
@@ -731,21 +731,19 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
}
NextSpeed.y += fallspeed;
}
- else
+
+ // Friction
+ if (NextSpeed.SqrLength() > 0.0004f)
{
- // Friction
- if (NextSpeed.SqrLength() > 0.0004f)
+ NextSpeed.x *= 0.7f / (1 + a_Dt);
+ if (fabs(NextSpeed.x) < 0.05)
{
- NextSpeed.x *= 0.7f / (1 + a_Dt);
- if (fabs(NextSpeed.x) < 0.05)
- {
- NextSpeed.x = 0;
- }
- NextSpeed.z *= 0.7f / (1 + a_Dt);
- if (fabs(NextSpeed.z) < 0.05)
- {
- NextSpeed.z = 0;
- }
+ NextSpeed.x = 0;
+ }
+ NextSpeed.z *= 0.7f / (1 + a_Dt);
+ if (fabs(NextSpeed.z) < 0.05)
+ {
+ NextSpeed.z = 0;
}
}
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 94df991a3..66c9aadeb 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -292,6 +292,10 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
Distance *= 2.5;
}
+ else if (IsSwimming())
+ {
+ Distance *= 1.3;
+ }
else
{
// Don't let the mob move too much if he's falling.
@@ -301,11 +305,13 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
AddSpeedX(Distance.x);
AddSpeedZ(Distance.z);
- if (m_EMState == ESCAPING)
- { // Runs Faster when escaping :D otherwise they just walk away
+ /* It's too buggy! */
+ /** if (m_EMState == ESCAPING)
+ {
+ // Runs Faster when escaping :D otherwise they just walk away
SetSpeedX (GetSpeedX() * 2.f);
SetSpeedZ (GetSpeedZ() * 2.f);
- }
+ } */
}
else
{
From 7bea90d6caca9f9b4389fe14ab49720f22cb9273 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 4 Aug 2014 01:35:25 +0200
Subject: [PATCH 087/751] Fixed warnings
---
src/Mobs/Monster.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 66c9aadeb..54ad869c2 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -290,16 +290,16 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
if (m_bOnGround)
{
- Distance *= 2.5;
+ Distance *= 2.5f;
}
else if (IsSwimming())
{
- Distance *= 1.3;
+ Distance *= 1.3f;
}
else
{
// Don't let the mob move too much if he's falling.
- Distance *= 0.25;
+ Distance *= 0.25f;
}
AddSpeedX(Distance.x);
From 122344bb7a71b7b4797869083c4c61f08882927a Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 4 Aug 2014 08:00:49 +0200
Subject: [PATCH 088/751] Rewritten string case manipulation to use
std::transform.
---
src/StringUtils.cpp | 26 ++++----------------------
1 file changed, 4 insertions(+), 22 deletions(-)
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index decce8065..0e30e8ebb 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -198,14 +198,7 @@ AString TrimString(const AString & str)
AString & StrToUpper(AString & s)
{
- AString::iterator i = s.begin();
- AString::iterator end = s.end();
-
- while (i != end)
- {
- *i = (char)toupper(*i);
- ++i;
- }
+ std::transform(s.begin(), s.end(), s.begin(), ::toupper);
return s;
}
@@ -215,14 +208,7 @@ AString & StrToUpper(AString & s)
AString & StrToLower(AString & s)
{
- AString::iterator i = s.begin();
- AString::iterator end = s.end();
-
- while (i != end)
- {
- *i = (char)tolower(*i);
- ++i;
- }
+ std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return s;
}
@@ -232,12 +218,8 @@ AString & StrToLower(AString & s)
AString StrToLower(const AString & s)
{
- AString res;
- res.resize(s.size());
- for (AString::iterator itr = res.begin(), end = res.end(); itr != end; ++itr)
- {
- *itr = (char)tolower(*itr);
- }
+ AString res(s);
+ std::transform(res.begin(), res.end(), res.begin(), ::tolower);
return res;
}
From e70077361d239f3f3a9d8a94c8262d663018f901 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 4 Aug 2014 11:23:35 +0200
Subject: [PATCH 089/751] Changed /** to /*
---
src/Mobs/Monster.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 54ad869c2..a9889b62f 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -305,13 +305,15 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
AddSpeedX(Distance.x);
AddSpeedZ(Distance.z);
- /* It's too buggy! */
- /** if (m_EMState == ESCAPING)
+ // It's too buggy!
+ /*
+ if (m_EMState == ESCAPING)
{
// Runs Faster when escaping :D otherwise they just walk away
SetSpeedX (GetSpeedX() * 2.f);
SetSpeedZ (GetSpeedZ() * 2.f);
- } */
+ }
+ */
}
else
{
From 8cdcfcceb38c057015d5822fa2ec06acf767f81d Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 4 Aug 2014 11:26:31 +0200
Subject: [PATCH 090/751] Changed properties for-loop.
---
src/Protocol/Protocol17x.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index d6f4b96dc..8f3399b2f 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -3035,7 +3035,7 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player)
const Json::Value & Properties = a_Player.GetClientHandle()->GetProperties();
Pkt.WriteVarInt(Properties.size());
- for (Json::Value::iterator itr = Properties.begin(); itr != Properties.end(); ++itr)
+ for (Json::Value::iterator itr = Properties.begin(), end = Properties.end(); itr != end; ++itr)
{
Pkt.WriteString(((Json::Value)*itr).get("name", "").asString());
Pkt.WriteString(((Json::Value)*itr).get("value", "").asString());
From 054ce9bcc45018b9f024654e7d35327fbc20d119 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 4 Aug 2014 11:29:40 +0200
Subject: [PATCH 091/751] Anvil: Wolf owner not saved if not present.
---
src/WorldStorage/NBTChunkSerializer.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index ecda9b8fd..e435a1b1f 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -570,8 +570,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
case cMonster::mtWolf:
{
const cWolf & Wolf = *((cWolf *)a_Monster);
- m_Writer.AddString("Owner", Wolf.GetOwnerName());
- m_Writer.AddString("OwnerUUID", Wolf.GetOwnerUUID());
+ if (!Wolf.GetOwnerName().empty())
+ {
+ m_Writer.AddString("Owner", Wolf.GetOwnerName());
+ }
+ if (!Wolf.GetOwnerUUID().empty())
+ {
+ m_Writer.AddString("OwnerUUID", Wolf.GetOwnerUUID());
+ }
m_Writer.AddByte("Sitting", Wolf.IsSitting() ? 1 : 0);
m_Writer.AddByte("Angry", Wolf.IsAngry() ? 1 : 0);
m_Writer.AddInt("CollarColor", Wolf.GetCollarColor());
From 1fa210c7f91030ac18fd880fcf131e8104c0b889 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 4 Aug 2014 11:16:19 +0200
Subject: [PATCH 092/751] Refactored case-conversion functions.
StrToLower() returns a modified copy of the string, InPlaceLowercase() modifies the string in-place.
---
src/HTTPServer/HTTPMessage.cpp | 3 +-
src/Mobs/Monster.cpp | 3 +-
src/Protocol/MojangAPI.cpp | 52 ++++++++++++++--------------------
src/Protocol/MojangAPI.h | 4 +--
src/StringUtils.cpp | 25 ++++++++++------
src/StringUtils.h | 7 +++--
src/WorldStorage/WSSAnvil.cpp | 7 ++++-
7 files changed, 54 insertions(+), 47 deletions(-)
diff --git a/src/HTTPServer/HTTPMessage.cpp b/src/HTTPServer/HTTPMessage.cpp
index 4226352e9..65d73fd87 100644
--- a/src/HTTPServer/HTTPMessage.cpp
+++ b/src/HTTPServer/HTTPMessage.cpp
@@ -35,8 +35,7 @@ cHTTPMessage::cHTTPMessage(eKind a_Kind) :
void cHTTPMessage::AddHeader(const AString & a_Key, const AString & a_Value)
{
- AString Key = a_Key;
- StrToLower(Key);
+ AString Key = StrToLower(a_Key);
cNameValueMap::iterator itr = m_Headers.find(Key);
if (itr == m_Headers.end())
{
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 94df991a3..53334753a 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -710,8 +710,7 @@ AString cMonster::MobTypeToString(cMonster::eType a_MobType)
cMonster::eType cMonster::StringToMobType(const AString & a_Name)
{
- AString lcName(a_Name);
- StrToLower(lcName);
+ AString lcName = StrToLower(a_Name);
// Binary-search for the lowercase name:
int lo = 0, hi = ARRAYCOUNT(g_MobTypeNames) - 1;
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 9fdf07380..a7aea5490 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -190,8 +190,7 @@ void cMojangAPI::Start(cIniFile & a_SettingsIni)
AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached)
{
// Convert the playername to lowercase:
- AString lcPlayerName(a_PlayerName);
- StrToLower(lcPlayerName);
+ AString lcPlayerName = StrToLower(a_PlayerName);
// Request the cache to query the name if not yet cached:
if (!a_UseOnlyCached)
@@ -219,7 +218,7 @@ AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_U
AString cMojangAPI::GetPlayerNameFromUUID(const AString & a_UUID, bool a_UseOnlyCached)
{
// Normalize the UUID to lowercase short format that is used as the map key:
- AString UUID = StrToLower(MakeUUIDShort(a_UUID));
+ AString UUID = MakeUUIDShort(a_UUID);
// Retrieve from caches:
{
@@ -260,8 +259,7 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player
AStringVector PlayerNames;
for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr)
{
- AString Lower(*itr);
- PlayerNames.push_back(StrToLower(Lower));
+ PlayerNames.push_back(StrToLower(*itr));
} // for itr - a_PlayerNames[]
// Request the cache to populate any names not yet contained:
@@ -292,12 +290,11 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player
void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID)
{
- AString lcName(a_PlayerName);
- AString UUID = StrToLower(MakeUUIDShort(a_UUID));
+ AString UUID = MakeUUIDShort(a_UUID);
Int64 Now = time(NULL);
{
cCSLock Lock(m_CSNameToUUID);
- m_NameToUUID[StrToLower(lcName)] = sProfile(a_PlayerName, UUID, "", "", Now);
+ m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, UUID, "", "", Now);
}
{
cCSLock Lock(m_CSUUIDToName);
@@ -311,12 +308,11 @@ void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const
void cMojangAPI::AddPlayerProfile(const AString & a_PlayerName, const AString & a_UUID, const Json::Value & a_Properties)
{
- AString lcName(a_PlayerName);
- AString UUID = StrToLower(MakeUUIDShort(a_UUID));
+ AString UUID = MakeUUIDShort(a_UUID);
Int64 Now = time(NULL);
{
cCSLock Lock(m_CSNameToUUID);
- m_NameToUUID[StrToLower(lcName)] = sProfile(a_PlayerName, UUID, "", "", Now);
+ m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, UUID, "", "", Now);
}
{
cCSLock Lock(m_CSUUIDToName);
@@ -395,13 +391,13 @@ AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
{
case 32:
{
- // Already is a short UUID
- return a_UUID;
+ // Already is a short UUID, only lowercase
+ return StrToLower(a_UUID);
}
case 36:
{
- // Remove the dashes from the string:
+ // Remove the dashes from the string by appending together the parts between them:
AString res;
res.reserve(32);
res.append(a_UUID, 0, 8);
@@ -409,7 +405,7 @@ AString cMojangAPI::MakeUUIDShort(const AString & a_UUID)
res.append(a_UUID, 14, 4);
res.append(a_UUID, 19, 4);
res.append(a_UUID, 24, 12);
- return res;
+ return StrToLower(res);
}
}
LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str());
@@ -427,8 +423,8 @@ AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID)
{
case 36:
{
- // Already is a dashed UUID
- return a_UUID;
+ // Already is a dashed UUID, only lowercase
+ return StrToLower(a_UUID);
}
case 32:
@@ -445,7 +441,7 @@ AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID)
res.append(a_UUID, 16, 4);
res.push_back('-');
res.append(a_UUID, 20, 12);
- return res;
+ return StrToLower(res);
}
}
LOGWARNING("%s: Not an UUID: \"%s\".", __FUNCTION__, a_UUID.c_str());
@@ -487,9 +483,8 @@ void cMojangAPI::LoadCachesFromDisk(void)
AString PlayerName = stmt.getColumn(0);
AString UUID = stmt.getColumn(1);
Int64 DateTime = stmt.getColumn(2);
- AString lcPlayerName = PlayerName;
- UUID = StrToLower(MakeUUIDShort(UUID));
- m_NameToUUID[StrToLower(lcPlayerName)] = sProfile(PlayerName, UUID, "", "", DateTime);
+ UUID = MakeUUIDShort(UUID);
+ m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, UUID, "", "", DateTime);
m_UUIDToName[UUID] = sProfile(PlayerName, UUID, "", "", DateTime);
}
}
@@ -502,9 +497,8 @@ void cMojangAPI::LoadCachesFromDisk(void)
AString Textures = stmt.getColumn(2);
AString TexturesSignature = stmt.getColumn(2);
Int64 DateTime = stmt.getColumn(4);
- AString lcPlayerName = PlayerName;
- UUID = StrToLower(MakeUUIDShort(UUID));
- m_UUIDToProfile[StrToLower(lcPlayerName)] = sProfile(PlayerName, UUID, Textures, TexturesSignature, DateTime);
+ UUID = MakeUUIDShort(UUID);
+ m_UUIDToProfile[UUID] = sProfile(PlayerName, UUID, Textures, TexturesSignature, DateTime);
}
}
}
@@ -669,13 +663,12 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
{
Json::Value & Val = root[idx];
AString JsonName = Val.get("name", "").asString();
- AString JsonUUID = StrToLower(MakeUUIDShort(Val.get("id", "").asString()));
+ AString JsonUUID = MakeUUIDShort(Val.get("id", "").asString());
if (JsonUUID.empty())
{
continue;
}
- AString lcName = JsonName;
- m_NameToUUID[StrToLower(lcName)] = sProfile(JsonName, JsonUUID, "", "", Now);
+ m_NameToUUID[StrToLower(JsonName)] = sProfile(JsonName, JsonUUID, "", "", Now);
} // for idx - root[]
} // cCSLock (m_CSNameToUUID)
@@ -686,7 +679,7 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
{
Json::Value & Val = root[idx];
AString JsonName = Val.get("name", "").asString();
- AString JsonUUID = StrToLower(MakeUUIDShort(Val.get("id", "").asString()));
+ AString JsonUUID = MakeUUIDShort(Val.get("id", "").asString());
if (JsonUUID.empty())
{
continue;
@@ -796,9 +789,8 @@ void cMojangAPI::CacheUUIDToProfile(const AString & a_UUID)
m_UUIDToName[a_UUID] = sProfile(PlayerName, a_UUID, Properties, Now);
}
{
- AString lcPlayerName(PlayerName);
cCSLock Lock(m_CSNameToUUID);
- m_NameToUUID[StrToLower(lcPlayerName)] = sProfile(PlayerName, a_UUID, Properties, Now);
+ m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, a_UUID, Properties, Now);
}
}
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index 08e799c73..6ed37625e 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -40,12 +40,12 @@ public:
// tolua_begin
- /** Converts the given UUID to its short form (32 bytes, no dashes).
+ /** Normalizes the given UUID to its short form (32 bytes, no dashes, lowercase).
Logs a warning and returns empty string if not a UUID.
Note: only checks the string's length, not the actual content. */
static AString MakeUUIDShort(const AString & a_UUID);
- /** Converts the given UUID to its dashed form (36 bytes, 4 dashes).
+ /** Normalizes the given UUID to its dashed form (36 bytes, 4 dashes, lowercase).
Logs a warning and returns empty string if not a UUID.
Note: only checks the string's length, not the actual content. */
static AString MakeUUIDDashed(const AString & a_UUID);
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 0e30e8ebb..5f88cbf64 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -196,9 +196,9 @@ AString TrimString(const AString & str)
-AString & StrToUpper(AString & s)
+AString & InPlaceLowercase(AString & s)
{
- std::transform(s.begin(), s.end(), s.begin(), ::toupper);
+ std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return s;
}
@@ -206,9 +206,9 @@ AString & StrToUpper(AString & s)
-AString & StrToLower(AString & s)
+AString & InPlaceUppercase(AString & s)
{
- std::transform(s.begin(), s.end(), s.begin(), ::tolower);
+ std::transform(s.begin(), s.end(), s.begin(), ::toupper);
return s;
}
@@ -227,16 +227,25 @@ AString StrToLower(const AString & s)
+AString StrToUpper(const AString & s)
+{
+ AString res(s);
+ std::transform(res.begin(), res.end(), res.begin(), ::toupper);
+ return res;
+}
+
+
+
+
+
int NoCaseCompare(const AString & s1, const AString & s2)
{
#ifdef _MSC_VER
// MSVC has stricmp that compares case-insensitive:
return _stricmp(s1.c_str(), s2.c_str());
#else
- // Do it the hard way:
- AString s1Copy(s1);
- AString s2Copy(s2);
- return StrToUpper(s1Copy).compare(StrToUpper(s2Copy));
+ // Do it the hard way - convert both strings to lowercase:
+ return StrToLower(s1).compare(StrToLower(s2));
#endif // else _MSC_VER
}
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 65363382d..142aaf59b 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -43,10 +43,13 @@ extern AStringVector StringSplitAndTrim(const AString & str, const AString & del
extern AString TrimString(const AString & str); // tolua_export
/// In-place string conversion to uppercase; returns the same string
-extern AString & StrToUpper(AString & s);
+extern AString & InPlaceUppercase(AString & s);
/// In-place string conversion to lowercase; returns the same string
-extern AString & StrToLower(AString & s);
+extern AString & InPlaceLowercase(AString & s);
+
+/** Returns an upper-cased copy of the string */
+extern AString StrToUpper(const AString & s);
/** Returns a lower-cased copy of the string */
extern AString StrToLower(const AString & s);
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 434f1e21f..a9c9ae4b5 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -2495,7 +2495,7 @@ void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_Ta
int OwnerUUIDIdx = a_NBT.FindChildByName(a_TagIdx, "OwnerUUID");
if (OwnerUUIDIdx > 0)
{
- OwnerUUID = cMojangAPI::MakeUUIDShort(a_NBT.GetString(OwnerUUIDIdx));
+ OwnerUUID = a_NBT.GetString(OwnerUUIDIdx);
}
int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
if (OwnerIdx > 0)
@@ -2520,6 +2520,11 @@ void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_Ta
return;
}
}
+ else
+ {
+ // Normalize the UUID:
+ OwnerUUID = cMojangAPI::MakeUUIDShort(OwnerUUID);
+ }
// Convert UUID to name, if needed:
if (OwnerName.empty())
From ff37192e945c9083d313ddc8924ef433e193f9c7 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 4 Aug 2014 12:03:37 +0200
Subject: [PATCH 093/751] BasicStyleCheck: Dividers are exactly 80 slashes.
---
src/CheckBasicStyle.lua | 18 +++++++++++++++++-
src/Mobs/Enderman.cpp | 2 +-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua
index 13a6d15d2..c743a84a5 100644
--- a/src/CheckBasicStyle.lua
+++ b/src/CheckBasicStyle.lua
@@ -10,11 +10,12 @@ Checks that all source files (*.cpp, *.h) use the basic style requirements of th
- Spaces after comma, not before
- Opening braces not at the end of a code line
- Spaces after if, for, while
+ - Line dividers (////...) exactly 80 slashes
- (TODO) Spaces before *, /, &
- (TODO) Hex numbers with even digit length
- (TODO) Hex numbers in lowercase
- - (TODO) Line dividers (////...) exactly 80 slashes
- (TODO) Not using "* "-style doxy comment continuation lines
+ - (TODO) Multi-level indent change
Violations that cannot be checked easily:
- Spaces around "+" (there are things like "a++", "++a", "a += 1", "X+", "stack +1" and ascii-drawn tables)
@@ -165,6 +166,21 @@ local function ProcessFile(a_FileName)
for _, pat in ipairs(g_ViolationPatterns) do
ReportViolationIfFound(a_Line, a_FileName, lineCounter, pat[1], pat[2])
end
+
+ local dividerStart, dividerEnd = a_Line:find("/////*")
+ if (dividerStart) then
+ if (dividerEnd ~= dividerStart + 79) then
+ ReportViolation(a_FileName, lineCounter, 1, 80, "Divider comment should have exactly 80 slashes")
+ end
+ if (dividerStart > 1) then
+ if (
+ (a_Line:sub(1, dividerStart - 1) ~= string.rep("\t", dividerStart - 1)) or -- The divider should have only indent in front of it
+ (a_Line:len() > dividerEnd + 1) -- The divider should have no other text following it
+ ) then
+ ReportViolation(a_FileName, lineCounter, 1, 80, "Divider comment shouldn't have any extra text around it")
+ end
+ end
+ end
lineCounter = lineCounter + 1
end
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 0a1b6491a..51255beb3 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -8,7 +8,7 @@
-///////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
// cPlayerLookCheck
class cPlayerLookCheck :
public cPlayerListCallback
From 7bfb0b05d0514c47095ba3ec8ebb6a1073d9962a Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 4 Aug 2014 13:20:16 +0200
Subject: [PATCH 094/751] CheckBasicStyle: multi-level indent change.
---
src/Bindings/WebPlugin.cpp | 2 ++
src/CheckBasicStyle.lua | 17 ++++++++++++++++-
src/Entities/HangingEntity.cpp | 2 +-
src/Generating/Noise3DGenerator.cpp | 5 +++--
src/Generating/StructGen.cpp | 6 +++---
src/Simulator/IncrementalRedstoneSimulator.cpp | 6 +++---
src/WorldStorage/WorldStorage.h | 8 +++++---
7 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/src/Bindings/WebPlugin.cpp b/src/Bindings/WebPlugin.cpp
index 1178c127a..4fa64d937 100644
--- a/src/Bindings/WebPlugin.cpp
+++ b/src/Bindings/WebPlugin.cpp
@@ -81,7 +81,9 @@ std::pair< AString, AString > cWebPlugin::GetTabNameForRequest(const HTTPRequest
else // Otherwise show the first tab
{
if (GetTabs().size() > 0)
+ {
Tab = *GetTabs().begin();
+ }
}
if (Tab != NULL)
diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua
index c743a84a5..bf81a7cd5 100644
--- a/src/CheckBasicStyle.lua
+++ b/src/CheckBasicStyle.lua
@@ -11,11 +11,11 @@ Checks that all source files (*.cpp, *.h) use the basic style requirements of th
- Opening braces not at the end of a code line
- Spaces after if, for, while
- Line dividers (////...) exactly 80 slashes
+ - Multi-level indent change
- (TODO) Spaces before *, /, &
- (TODO) Hex numbers with even digit length
- (TODO) Hex numbers in lowercase
- (TODO) Not using "* "-style doxy comment continuation lines
- - (TODO) Multi-level indent change
Violations that cannot be checked easily:
- Spaces around "+" (there are things like "a++", "++a", "a += 1", "X+", "stack +1" and ascii-drawn tables)
@@ -159,6 +159,7 @@ local function ProcessFile(a_FileName)
-- Process each line separately:
-- Ref.: http://stackoverflow.com/questions/10416869/iterate-over-possibly-empty-lines-in-a-way-that-matches-the-expectations-of-exis
local lineCounter = 1
+ local lastIndentLevel = 0
all:gsub("\r\n", "\n") -- normalize CRLF into LF-only
string.gsub(all .. "\n", "[^\n]*\n", -- Iterate over each line, while preserving empty lines
function(a_Line)
@@ -167,6 +168,7 @@ local function ProcessFile(a_FileName)
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
if (dividerEnd ~= dividerStart + 79) then
@@ -181,6 +183,19 @@ 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
+ if (indentStart) then
+ indentLevel = indentEnd - indentStart
+ end
+ if (indentLevel > 0) then
+ if ((lastIndentLevel - indentLevel >= 2) or (lastIndentLevel - indentLevel <= -2)) then
+ ReportViolation(a_FileName, lineCounter, 1, indentStart or 1, "Indent changed more than a single level between the previous line and this one: from " .. lastIndentLevel .. " to " .. indentLevel)
+ end
+ lastIndentLevel = indentLevel
+ end
lineCounter = lineCounter + 1
end
diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp
index 32d2b226d..8c70c606e 100644
--- a/src/Entities/HangingEntity.cpp
+++ b/src/Entities/HangingEntity.cpp
@@ -24,7 +24,7 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace,
void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
{
int Dir = 0;
-
+
// The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
switch (m_BlockFace)
{
diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp
index b879349ee..eb816f564 100644
--- a/src/Generating/Noise3DGenerator.cpp
+++ b/src/Generating/Noise3DGenerator.cpp
@@ -412,11 +412,12 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
for (int x = 0; x < 17; x += UPSCALE_X)
{
NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(a_ChunkX * cChunkDef::Width + x)) / m_FrequencyX;
- CurFloor[x + 17 * z] =
+ CurFloor[x + 17 * z] = (
m_Noise1.CubicNoise3D(NoiseX, NoiseY, NoiseZ) * (NOISE_DATATYPE)0.5 +
m_Noise2.CubicNoise3D(NoiseX / 2, NoiseY / 2, NoiseZ / 2) +
m_Noise3.CubicNoise3D(NoiseX / 4, NoiseY / 4, NoiseZ / 4) * 2 +
- AddHeight / Height[x + 17 * z];
+ AddHeight / Height[x + 17 * z]
+ );
}
}
// Linear-interpolate this XZ floor:
diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp
index 054eec345..f7e609353 100644
--- a/src/Generating/StructGen.cpp
+++ b/src/Generating/StructGen.cpp
@@ -585,10 +585,10 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc)
// First update the high floor:
for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++)
{
- FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] =
+ FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = (
m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) *
- m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) /
- 256;
+ m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256
+ );
} // for x, z - FloorLo[]
LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi);
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp
index ada8de4b8..c1a2fcaae 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator.cpp
@@ -847,7 +847,7 @@ void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_RelBlockX, int a_Rel
bool m_IsPowered;
public:
cSetPowerToDropSpenser(bool a_IsPowered) : m_IsPowered(a_IsPowered) {}
-
+
virtual bool Item(cDropSpenserEntity * a_DropSpenser) override
{
a_DropSpenser->SetRedstonePower(m_IsPowered);
@@ -948,7 +948,7 @@ void cIncrementalRedstoneSimulator::HandleCommandBlock(int a_RelBlockX, int a_Re
bool m_IsPowered;
public:
cSetPowerToCommandBlock(bool a_IsPowered) : m_IsPowered(a_IsPowered) {}
-
+
virtual bool Item(cCommandBlockEntity * a_CommandBlock) override
{
a_CommandBlock->SetRedstonePower(m_IsPowered);
@@ -1844,7 +1844,7 @@ void cIncrementalRedstoneSimulator::SetDirectionLinkedPowered(int a_RelBlockX, i
{
return;
}
-
+
SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 2, a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel);
SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel);
SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel);
diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h
index 5d8aa4589..dd07ecb64 100644
--- a/src/WorldStorage/WorldStorage.h
+++ b/src/WorldStorage/WorldStorage.h
@@ -95,9 +95,11 @@ protected:
bool operator ==(const sChunkLoad other) const
{
- return this->m_ChunkX == other.m_ChunkX &&
- this->m_ChunkY == other.m_ChunkY &&
- this->m_ChunkZ == other.m_ChunkZ;
+ return (
+ (this->m_ChunkX == other.m_ChunkX) &&
+ (this->m_ChunkY == other.m_ChunkY) &&
+ (this->m_ChunkZ == other.m_ChunkZ)
+ );
}
} ;
From 01e9d6311a4c27af044e8c9be3c67000124321e9 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Mon, 4 Aug 2014 14:24:46 +0100
Subject: [PATCH 095/751] Updated submodules
---
MCServer/Plugins/Core | 2 +-
MCServer/Plugins/ProtectionAreas | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core
index 3790f78d3..1b16c23c2 160000
--- a/MCServer/Plugins/Core
+++ b/MCServer/Plugins/Core
@@ -1 +1 @@
-Subproject commit 3790f78d3f7503ff33a423b8e73e81a275562783
+Subproject commit 1b16c23c216d359e9fe0334c63deeecc347e69bd
diff --git a/MCServer/Plugins/ProtectionAreas b/MCServer/Plugins/ProtectionAreas
index 9edfee930..7765048fa 160000
--- a/MCServer/Plugins/ProtectionAreas
+++ b/MCServer/Plugins/ProtectionAreas
@@ -1 +1 @@
-Subproject commit 9edfee93048f214175cbed7eb2a3f77f7ac4abb2
+Subproject commit 7765048fa740b8f119db72a4ccc546504f86b2ab
From f5b71cc1f86c383891d2c0da7a3be5355ee1816e Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 4 Aug 2014 20:16:52 +0200
Subject: [PATCH 096/751] Fixed #1286
---
src/Protocol/Protocol17x.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 8f3399b2f..318342f09 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -820,7 +820,7 @@ void cProtocol172::SendPlayerAbilities(void)
}
Pkt.WriteByte(Flags);
Pkt.WriteFloat((float)(0.05 * Player->GetFlyingMaxSpeed()));
- Pkt.WriteFloat((float)(0.1 * Player->GetMaxSpeed()));
+ Pkt.WriteFloat((float)(0.1 * Player->GetNormalMaxSpeed()));
}
From 434ea542e174bc686a7c981476e23d30d18989c3 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 4 Aug 2014 21:48:33 +0200
Subject: [PATCH 097/751] Added arrow consuming on shooting
---
src/Items/ItemBow.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h
index e7a77dcbc..90645dd9a 100644
--- a/src/Items/ItemBow.h
+++ b/src/Items/ItemBow.h
@@ -57,6 +57,12 @@ public:
}
Force = std::min(Force, 1.0);
+ // Has the player a arrow?
+ if (!a_Player->IsGameModeCreative() && !a_Player->GetInventory().HasItems(cItem(E_ITEM_ARROW)))
+ {
+ return;
+ }
+
// Create the arrow entity:
cArrowEntity * Arrow = new cArrowEntity(*a_Player, Force * 2);
if (Arrow == NULL)
@@ -73,6 +79,10 @@ public:
a_Player->GetWorld()->BroadcastSoundEffect("random.bow", a_Player->GetPosX(), a_Player->GetPosY(), a_Player->GetPosZ(), 0.5, (float)Force);
if (!a_Player->IsGameModeCreative())
{
+ if (a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchInfinity) == 0)
+ {
+ a_Player->GetInventory().RemoveItem(cItem(E_ITEM_ARROW));
+ }
a_Player->UseEquippedItem();
}
}
From de9d908792c7dfbc13db87a3508a8c4b0516d01c Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Mon, 4 Aug 2014 21:21:35 +0100
Subject: [PATCH 098/751] Made AllToLua output consistent
---
src/Bindings/gen_LuaState_Call.lua | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Bindings/gen_LuaState_Call.lua b/src/Bindings/gen_LuaState_Call.lua
index fb1797dc0..17bae82b3 100644
--- a/src/Bindings/gen_LuaState_Call.lua
+++ b/src/Bindings/gen_LuaState_Call.lua
@@ -13,7 +13,7 @@ separate the arguments from the return values, a special type of cLuaState::cRet
-print("Generating LuaState_Call.inc...")
+print("Generating LuaState_Call.inc . . .")
@@ -189,7 +189,7 @@ f:close()
-print("LuaState_Call.inc generated")
+print("LuaState_Call.inc generated.")
From 0b9eb20b92f49feeb34626eef4590f7938a93480 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Mon, 4 Aug 2014 21:22:08 +0100
Subject: [PATCH 099/751] Fixed signs not staying on other signs
---
src/Blocks/BlockSignPost.h | 3 ++-
src/Blocks/BlockWallSign.h | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/Blocks/BlockSignPost.h b/src/Blocks/BlockSignPost.h
index ee65d099a..d0cc760b0 100644
--- a/src/Blocks/BlockSignPost.h
+++ b/src/Blocks/BlockSignPost.h
@@ -39,8 +39,9 @@ public:
{
return false;
}
+ BLOCKTYPE Type = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
- return (cBlockInfo::IsSolid(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)));
+ return ((Type == E_BLOCK_SIGN_POST) || cBlockInfo::IsSolid(Type));
}
diff --git a/src/Blocks/BlockWallSign.h b/src/Blocks/BlockWallSign.h
index e837b315e..47649379e 100644
--- a/src/Blocks/BlockWallSign.h
+++ b/src/Blocks/BlockWallSign.h
@@ -49,8 +49,9 @@ public:
int BlockX = (a_Chunk.GetPosX() * cChunkDef::Width) + a_RelX;
int BlockZ = (a_Chunk.GetPosZ() * cChunkDef::Width) + a_RelZ;
GetBlockCoordsBehindTheSign(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ), BlockX, BlockZ);
+ BLOCKTYPE Type = a_ChunkInterface.GetBlock(BlockX, a_RelY, BlockZ);
- return (cBlockInfo::IsSolid(a_ChunkInterface.GetBlock(BlockX, a_RelY, BlockZ)));
+ return ((Type == E_BLOCK_WALLSIGN) || (Type == E_BLOCK_SIGN_POST) || cBlockInfo::IsSolid(Type));
}
From 2e43eaaba7a29a9db5bfa11d6a1bb8b57bf02fa6 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 4 Aug 2014 22:30:13 +0200
Subject: [PATCH 100/751] Changed arrow comment.
---
src/Items/ItemBow.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h
index 90645dd9a..fdc24689c 100644
--- a/src/Items/ItemBow.h
+++ b/src/Items/ItemBow.h
@@ -57,7 +57,7 @@ public:
}
Force = std::min(Force, 1.0);
- // Has the player a arrow?
+ // Does the player have an arrow?
if (!a_Player->IsGameModeCreative() && !a_Player->GetInventory().HasItems(cItem(E_ITEM_ARROW)))
{
return;
From 9113b45673bc9b0202ce821b8db2dbe6f4b425b9 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 4 Aug 2014 23:35:32 +0200
Subject: [PATCH 101/751] MojangAPI: Fixed PlayerNameToUUID().
---
src/Protocol/MojangAPI.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index a7aea5490..823ff5469 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -208,7 +208,7 @@ AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_U
// No UUID found
return "";
}
- return itr->second.m_PlayerName;
+ return itr->second.m_UUID;
}
From d2d0ffee21d10aace8caa20a002daa1c887c1f39 Mon Sep 17 00:00:00 2001
From: archshift
Date: Mon, 4 Aug 2014 19:43:33 -0700
Subject: [PATCH 102/751] Fixed unsigned long comparison to size_t
---
src/Items/ItemHandler.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index 1c1e3b5b9..bceedaf69 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -66,7 +66,7 @@ cItemHandler * cItemHandler::m_ItemHandler[2268];
cItemHandler * cItemHandler::GetItemHandler(int a_ItemType)
{
- if ((a_ItemType < 0) || ((unsigned long)a_ItemType >= ARRAYCOUNT(m_ItemHandler)))
+ if ((a_ItemType < 0) || ((size_t)a_ItemType >= ARRAYCOUNT(m_ItemHandler)))
{
// Either nothing (-1), or bad value, both cases should return the air handler
if (a_ItemType < -1)
From a92cff20ea59b68827a6f579d0ba9ccb40276d6b Mon Sep 17 00:00:00 2001
From: Howaner
Date: Tue, 5 Aug 2014 13:47:10 +0200
Subject: [PATCH 103/751] Added Clamp() function to the lua api.
---
src/Bindings/ManualBindings.cpp | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 042ffb19e..b41cd94bc 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -82,6 +82,33 @@ static int lua_do_error(lua_State* L, const char * a_pFormat, ...)
// Lua bound functions with special return types
+static int tolua_Clamp(lua_State * tolua_S)
+{
+ cLuaState LuaState(tolua_S);
+ int NumArgs = lua_gettop(LuaState);
+ if (NumArgs != 3)
+ {
+ return lua_do_error(LuaState, "Error in function call '#funcname#': Requires 3 arguments, got %i", NumArgs);
+ }
+
+ if (!lua_isnumber(LuaState, 1) || !lua_isnumber(LuaState, 2) || !lua_isnumber(LuaState, 3))
+ {
+ return lua_do_error(LuaState, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3");
+ }
+
+ int Min = (int)tolua_tonumber(LuaState, 1, 0);
+ int Number = (int)tolua_tonumber(LuaState, 2, 0);
+ int Max = (int)tolua_tonumber(LuaState, 3, 0);
+
+ int Result = std::min(std::max(Min, Number), Max);
+ LuaState.Push(Result);
+ return 1;
+}
+
+
+
+
+
static int tolua_StringSplit(lua_State * tolua_S)
{
cLuaState LuaState(tolua_S);
@@ -3103,6 +3130,7 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S)
void ManualBindings::Bind(lua_State * tolua_S)
{
tolua_beginmodule(tolua_S, NULL);
+ tolua_function(tolua_S, "Clamp", tolua_Clamp);
tolua_function(tolua_S, "StringSplit", tolua_StringSplit);
tolua_function(tolua_S, "StringSplitAndTrim", tolua_StringSplitAndTrim);
tolua_function(tolua_S, "LOG", tolua_LOG);
From 43de9af8786243c90832b78f8c19ec92fb218392 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Tue, 5 Aug 2014 13:54:04 +0200
Subject: [PATCH 104/751] Added api documentation for Clamp()
---
MCServer/Plugins/APIDump/APIDesc.lua | 5 +++--
src/Bindings/ManualBindings.cpp | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index ad3b24ca5..64ba80c5f 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2760,15 +2760,16 @@ end
Functions =
{
AddFaceDirection = {Params = "BlockX, BlockY, BlockZ, BlockFace, [IsInverse]", Return = "BlockX, BlockY, BlockZ", Notes = "Returns the coords of a block adjacent to the specified block through the specified {{Globals#BlockFaces|face}}"},
- BlockFaceToString = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "string", Notes = "Returns the string representation of the {{Globals#BlockFaces|eBlockFace}} constant. Uses the axis-direction-based names, such as BLOCK_FACE_XP." },
+ BlockFaceToString = {Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "string", Notes = "Returns the string representation of the {{Globals#BlockFaces|eBlockFace}} constant. Uses the axis-direction-based names, such as BLOCK_FACE_XP." },
BlockStringToType = {Params = "BlockTypeString", Return = "BLOCKTYPE", Notes = "Returns the block type parsed from the given string"},
+ Clamp = {Params = "Number, Min, Max", Return = "number", Notes = "Clamp the number to the specified range."},
ClickActionToString = {Params = "{{Globals#ClickAction|ClickAction}}", Return = "string", Notes = "Returns a string description of the ClickAction enumerated value"},
DamageTypeToString = {Params = "{{Globals#DamageType|DamageType}}", Return = "string", Notes = "Converts the {{Globals#DamageType|DamageType}} enumerated value to a string representation "},
EscapeString = {Params = "string", Return = "string", Notes = "Returns a copy of the string with all quotes and backslashes escaped by a backslash"},
GetChar = {Params = "String, Pos", Return = "string", Notes = "Returns one character from the string, specified by position "},
GetIniItemSet = { Params = "IniFile, SectionName, KeyName, DefaultValue", Return = "{{cItem}}", Notes = "Returns the item that has been read from the specified INI file value. If the value is not present in the INI file, the DefaultValue is stored in the file and parsed as the result. Returns empty item if the value cannot be parsed. " },
GetTime = {Return = "number", Notes = "Returns the current OS time, as a unix time stamp (number of seconds since Jan 1, 1970)"},
- IsBiomeNoDownfall = { Params = "Biome", Return = "bool", Notes = "Returns true if the biome is 'dry', that is, there is no precipitation during rains and storms." },
+ IsBiomeNoDownfall = {Params = "Biome", Return = "bool", Notes = "Returns true if the biome is 'dry', that is, there is no precipitation during rains and storms." },
IsValidBlock = {Params = "BlockType", Return = "bool", Notes = "Returns true if BlockType is a known block type"},
IsValidItem = {Params = "ItemType", Return = "bool", Notes = "Returns true if ItemType is a known item type"},
ItemToFullString = {Params = "{{cItem|cItem}}", Return = "string", Notes = "Returns the string representation of the item, in the format 'ItemTypeText:ItemDamage * Count'"},
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index b41cd94bc..81065a7e1 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -96,8 +96,8 @@ static int tolua_Clamp(lua_State * tolua_S)
return lua_do_error(LuaState, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3");
}
- int Min = (int)tolua_tonumber(LuaState, 1, 0);
- int Number = (int)tolua_tonumber(LuaState, 2, 0);
+ int Number = (int)tolua_tonumber(LuaState, 1, 0);
+ int Min = (int)tolua_tonumber(LuaState, 2, 0);
int Max = (int)tolua_tonumber(LuaState, 3, 0);
int Result = std::min(std::max(Min, Number), Max);
From 40e15c5ad517a6f860b39d1b225596424c3d2506 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 5 Aug 2014 18:37:00 +0200
Subject: [PATCH 105/751] RankMgr: Initial interface declaration.
---
src/CMakeLists.txt | 2 +
src/RankManager.cpp | 153 ++++++++++++++++++++++++++++++++++++++++++++
src/RankManager.h | 103 +++++++++++++++++++++++++++++
3 files changed, 258 insertions(+)
create mode 100644 src/RankManager.cpp
create mode 100644 src/RankManager.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index db9c61082..d6066b38b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -52,6 +52,7 @@ SET (SRCS
MonsterConfig.cpp
Noise.cpp
ProbabDistrib.cpp
+ RankManager.cpp
RCONServer.cpp
Root.cpp
Scoreboard.cpp
@@ -121,6 +122,7 @@ SET (HDRS
MonsterConfig.h
Noise.h
ProbabDistrib.h
+ RankManager.h
RCONServer.h
Root.h
Scoreboard.h
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
new file mode 100644
index 000000000..954edd099
--- /dev/null
+++ b/src/RankManager.cpp
@@ -0,0 +1,153 @@
+
+// RankManager.cpp
+
+// Implements the cRankManager class that represents the rank manager responsible for assigning permissions and message visuals to players
+
+#include "Globals.h"
+#include "RankManager.h"
+#include "Protocol/MojangAPI.h"
+#include "inifile/iniFile.h"
+#include
+
+
+
+
+
+/*
+// This code is for internal testing while developing the cRankManager class
+static class cRankMgrTest
+{
+public:
+ cRankMgrTest(void) :
+ m_Mgr()
+ {
+ // Initialize the cMojangAPI so that it can convert playernames to UUIDs:
+ cIniFile Ini;
+ Ini.ReadFile("settings.ini");
+ m_API.Start(Ini);
+
+ // Test the cRankManager class:
+ ReportPlayer("xoft");
+ }
+
+ void ReportPlayer(const AString & a_PlayerName)
+ {
+ // Get the player's UUID and rank:
+ AString UUID = m_API.GetUUIDFromPlayerName(a_PlayerName);
+ std::cout << "Player " << a_PlayerName << " has UUID '" << UUID <<"'." << std::endl;
+ std::cout << " Rank: '" << m_Mgr.GetPlayerRankName(UUID) << "'." << std::endl;
+
+ // List all the permission groups for the player:
+ AStringVector Groups = m_Mgr.GetPlayerPermissionGroups(UUID);
+ std::cout << " Groups(" << Groups.size() << "):" << std::endl;
+ for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
+ {
+ std::cout << " '" << *itr << "'." << std::endl;
+ } // for itr - Groups[]
+
+ // List all the permissions for the player:
+ AStringVector Permissions = m_Mgr.GetPlayerPermissions(UUID);
+ std::cout << " Permissions(" << Permissions.size() << "):" << std::endl;
+ for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
+ {
+ std::cout << " '" << *itr << "'." << std::endl;
+ } // for itr - Groups[]
+
+ std::cout << "Done." << std::endl;
+ }
+
+protected:
+ cRankManager m_Mgr;
+ cMojangAPI m_API;
+} g_RankMgrTest;
+//*/
+
+
+
+
+
+cRankManager::cRankManager(void) :
+ m_DB("Ranks.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)
+{
+ // Create the DB tables, if they don't exist:
+ m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID, Name, MsgPrefix, MsgPostfix, MsgNameColorCode)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionGroup (GroupID, Name)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermissionGroups (RankID, GroupID)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (GroupID, Permission)");
+
+ // TODO: Check if tables empty, add some defaults then
+}
+
+
+
+
+
+AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
+{
+ SQLite::Statement stmt(m_DB, "SELECT Rank.Name FROM Rank LEFT JOIN PlayerRank ON Rank.RankID = PlayerRank.RankID WHERE PlayerRank.PlayerUUID = ?");
+ stmt.bind(1, a_PlayerUUID);
+ stmt.executeStep();
+ if (stmt.isDone())
+ {
+ // No data returned from the DB
+ return AString();
+ }
+ return stmt.getColumn(0).getText();
+}
+
+
+
+
+
+AStringVector cRankManager::GetPlayerPermissionGroups(const AString & a_PlayerUUID)
+{
+ // Prepare the DB statement:
+ SQLite::Statement stmt(m_DB,
+ "SELECT PermissionGroup.Name FROM PermissionGroup "
+ "LEFT JOIN RankPermissionGroups "
+ "ON PermissionGroup.GroupID = RankPermissionGroups.GroupID "
+ "LEFT JOIN PlayerRank "
+ "ON PlayerRank.RankID = RankPermissionGroups.RankID "
+ "WHERE PlayerRank.PlayerUUID = ?"
+ );
+ stmt.bind(1, a_PlayerUUID);
+
+ // Execute and get results:
+ AStringVector res;
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ return res;
+}
+
+
+
+
+
+AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
+{
+ // Prepare the DB statement:
+ SQLite::Statement stmt(m_DB,
+ "SELECT PermissionItem.Permission FROM PermissionItem "
+ "LEFT JOIN RankPermissionGroups "
+ "ON PermissionItem.GroupID = RankPermissionGroups.GroupID "
+ "LEFT JOIN PlayerRank "
+ "ON PlayerRank.RankID = RankPermissionGroups.RankID "
+ "WHERE PlayerRank.PlayerUUID = ?"
+ );
+ stmt.bind(1, a_PlayerUUID);
+
+ // Execute and get results:
+ AStringVector res;
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ return res;
+}
+
+
+
+
diff --git a/src/RankManager.h b/src/RankManager.h
new file mode 100644
index 000000000..cda6beee9
--- /dev/null
+++ b/src/RankManager.h
@@ -0,0 +1,103 @@
+
+// RankManager.h
+
+// Declares the cRankManager class that represents the rank manager responsible for assigning permissions and message visuals to players
+
+
+
+
+#pragma once
+
+#include "SQLiteCpp/Database.h"
+
+
+
+
+
+class cRankManager
+{
+public:
+ cRankManager(void);
+
+ /** Returns the name of the rank that the specified player has assigned to them. */
+ AString GetPlayerRankName(const AString & a_PlayerUUID);
+
+ /** Returns the names of PermissionGroups that the specified player has assigned to them. */
+ AStringVector GetPlayerPermissionGroups(const AString & a_PlayerUUID);
+
+ /** Returns the permissions that the specified player has assigned to them. */
+ AStringVector GetPlayerPermissions(const AString & a_PlayerUUID);
+
+ /** Returns the names of groups that the specified rank has assigned to it. */
+ AStringVector GetRankPermissionGroups(const AString & a_RankName);
+
+ /** Returns the permissions that the specified permission group has assigned to it. */
+ AStringVector GetPermissionGroupPermissiont(const AString & a_GroupName);
+
+ /** Returns the names of all defined ranks. */
+ AStringVector GetAllRanks(void);
+
+ /** Returns the names of all permission groups. */
+ AStringVector GetAllPermissionGroups(void);
+
+ /** Returns all the distinct permissions that are stored in the DB. */
+ AStringVector GetAllPermissions(void);
+
+ /** Returns the message visuals (prefix, postfix, color) for the specified player. */
+ void GetPlayerMsgVisuals(
+ const AString & a_PlayerUUID,
+ AString & a_MsgPrefix,
+ AString & a_MsgPostfix,
+ AString & a_MsgNameColorCode
+ );
+
+ /** Adds a new rank. No action if the rank already exists. */
+ void AddRank(const AString & a_RankName);
+
+ /** Adds a new permission group. No action if such a group already exists. */
+ void AddPermissionGroup(const AString & a_GroupName);
+
+ /** Adds the specified permission group to the specified rank.
+ Fails if the rank or group names are not found.
+ Returns true if successful, false on error. */
+ bool AddPermissionGroupToRank(const AString & a_RankName, const AString & a_GroupName);
+
+ /** Adds the specified permission to the specified permission group.
+ Fails if the permission group name is not found.
+ Returns true if successful, false on error. */
+ bool AddPermissionToPermissionGroup(const AString & a_Permission, const AString & a_GroupName);
+
+ /** Removes the specified rank.
+ All players assigned to that rank will be re-assigned to a_ReplacementRankName, unless it is empty. */
+ void RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName);
+
+ /** Removes the specified permission group. */
+ void RemovePermissionGroup(const AString & a_PermissionGroup);
+
+ /** Removes the specified permission from the specified permission group. */
+ void RemovePermission(const AString & a_Permission, const AString & a_PermissionGroup);
+
+ /** Renames the specified rank. No action if the rank name is not found.
+ Fails if the new name is already used.
+ Returns true on success, false on failure. */
+ bool RenameRank(const AString & a_OldName, const AString & a_NewName);
+
+ /** Renames the specified permission group. No action if the rank name is not found.
+ Fails if the new name is already used.
+ Returns true on success, false on failure. */
+ bool RenamePermissionGroup(const AString & a_OldName, const AString & a_NewName);
+
+ /** Sets the specified player's rank.
+ If the player already had rank assigned to them, it is overwritten with the new rank.
+ Note that this doesn't change the cPlayer if the player is already connected, you need to update all the
+ cPlayer instances manually. */
+ void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_RankName);
+
+protected:
+
+ SQLite::Database m_DB;
+} ;
+
+
+
+
From 5f04488a97b5cdd705368937d977827ef4465d4a Mon Sep 17 00:00:00 2001
From: Howaner
Date: Tue, 5 Aug 2014 18:39:18 +0200
Subject: [PATCH 106/751] Made lua clamp() compatible with all number types.
---
src/Bindings/ManualBindings.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 81065a7e1..9ba1501c5 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -96,11 +96,11 @@ static int tolua_Clamp(lua_State * tolua_S)
return lua_do_error(LuaState, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3");
}
- int Number = (int)tolua_tonumber(LuaState, 1, 0);
- int Min = (int)tolua_tonumber(LuaState, 2, 0);
- int Max = (int)tolua_tonumber(LuaState, 3, 0);
+ lua_Number Number = tolua_tonumber(LuaState, 1, 0);
+ lua_Number Min = tolua_tonumber(LuaState, 2, 0);
+ lua_Number Max = tolua_tonumber(LuaState, 3, 0);
- int Result = std::min(std::max(Min, Number), Max);
+ lua_Number Result = Clamp(Number, Min, Max);
LuaState.Push(Result);
return 1;
}
From fcfae0252503a845c98fe6e882dda69e44224094 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 5 Aug 2014 22:28:37 +0200
Subject: [PATCH 107/751] RankMgr: More interface.
---
src/RankManager.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/RankManager.h b/src/RankManager.h
index cda6beee9..1eaeb97a1 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -47,12 +47,17 @@ public:
void GetPlayerMsgVisuals(
const AString & a_PlayerUUID,
AString & a_MsgPrefix,
- AString & a_MsgPostfix,
+ AString & a_MsgSuffix,
AString & a_MsgNameColorCode
);
/** Adds a new rank. No action if the rank already exists. */
- void AddRank(const AString & a_RankName);
+ void AddRank(
+ const AString & a_RankName,
+ const AString & a_MsgPrefix,
+ const AString & a_MsgSuffix,
+ const AString & a_MsgNameColorCode
+ );
/** Adds a new permission group. No action if such a group already exists. */
void AddPermissionGroup(const AString & a_GroupName);
@@ -93,6 +98,13 @@ public:
cPlayer instances manually. */
void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_RankName);
+ /** Sets the message visuals of an existing rank. No action if the rank name is not found. */
+ void SetRankVisuals(
+ const AString & a_RankName,
+ const AString & a_MsgPrefix,
+ const AString & a_MsgSuffix,
+ const AString & a_MsgNameColorCode
+ );
protected:
SQLite::Database m_DB;
From a717a7e712e6be1e6980cade95f09b5b85bdfe67 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 5 Aug 2014 22:32:26 +0200
Subject: [PATCH 108/751] RankMgr: Added SQL integer datatypes.
---
src/RankManager.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index 954edd099..18ed65b26 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -70,11 +70,11 @@ cRankManager::cRankManager(void) :
m_DB("Ranks.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)
{
// Create the DB tables, if they don't exist:
- m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID, Name, MsgPrefix, MsgPostfix, MsgNameColorCode)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionGroup (GroupID, Name)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermissionGroups (RankID, GroupID)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (GroupID, Permission)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID INTEGER PRIMARY KEY, Name, MsgPrefix, MsgPostfix, MsgNameColorCode)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID INTEGER)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionGroup (GroupID INTEGER PRIMARY KEY, Name)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermissionGroups (RankID INTEGER, GroupID INTEGER)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (GroupID INTEGER, Permission)");
// TODO: Check if tables empty, add some defaults then
}
From 06942871dde1388284a4fe222040720de3923b03 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Tue, 5 Aug 2014 21:48:23 +0100
Subject: [PATCH 109/751] Refactored Redstone simulator not to depend on
TNTEntity or DropSpenserENtity Directly
---
src/BlockEntities/DropSpenserEntity.h | 7 ++--
src/BlockEntities/RedstonePoweredEntity.h | 9 +++++
src/Chunk.cpp | 34 +++++++++++++++++++
src/Chunk.h | 6 +++-
.../IncrementalRedstoneSimulator.cpp | 9 +++--
5 files changed, 56 insertions(+), 9 deletions(-)
create mode 100644 src/BlockEntities/RedstonePoweredEntity.h
diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h
index 9f58d0b07..dabe9a27b 100644
--- a/src/BlockEntities/DropSpenserEntity.h
+++ b/src/BlockEntities/DropSpenserEntity.h
@@ -11,7 +11,7 @@
#pragma once
#include "BlockEntityWithItems.h"
-
+#include "RedstonePoweredEntity.h"
@@ -30,7 +30,8 @@ class cServer;
// tolua_begin
class cDropSpenserEntity :
- public cBlockEntityWithItems
+ public cBlockEntityWithItems,
+ public cRedstonePoweredEntity
{
typedef cBlockEntityWithItems super;
@@ -65,7 +66,7 @@ public:
void Activate(void);
/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
- void SetRedstonePower(bool a_IsPowered);
+ virtual void SetRedstonePower(bool a_IsPowered) override;
// tolua_end
diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h
new file mode 100644
index 000000000..aebba771f
--- /dev/null
+++ b/src/BlockEntities/RedstonePoweredEntity.h
@@ -0,0 +1,9 @@
+
+
+// Interface class representing a blockEntity that responds to redstone
+class cRedstonePoweredEntity
+{
+public:
+/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
+ virtual void SetRedstonePower(bool a_IsPowered) = 0;
+};
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index cd7dc698c..9e06f58ec 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -2127,6 +2127,40 @@ bool cChunk::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBloc
+bool cChunk::DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cRedstonePoweredCallback & a_Callback)
+{
+ // The blockentity list is locked by the parent chunkmap's CS
+ for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2)
+ {
+ ++itr2;
+ if (((*itr)->GetPosX() != a_BlockX) || ((*itr)->GetPosY() != a_BlockY) || ((*itr)->GetPosZ() != a_BlockZ))
+ {
+ continue;
+ }
+ switch ((*itr)->GetBlockType())
+ {
+ case E_BLOCK_DROPPER:
+ case E_BLOCK_DISPENSER:
+ break;
+ default:
+ // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out
+ return false;
+ }
+
+ if (a_Callback.Item((cRedstonePoweredEntity *)*itr))
+ {
+ return false;
+ }
+ return true;
+ } // for itr - m_BlockEntitites[]
+
+ // Not found:
+ return false;
+}
+
+
+
+
bool cChunk::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback)
{
// The blockentity list is locked by the parent chunkmap's CS
diff --git a/src/Chunk.h b/src/Chunk.h
index 5cde3f08f..813a8b13f 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -43,6 +43,7 @@ class cBlockArea;
class cFluidSimulatorData;
class cMobCensus;
class cMobSpawner;
+class cRedstonePoweredEntity;
typedef std::list cClientHandleList;
typedef cItemCallback cEntityCallback;
@@ -54,6 +55,7 @@ typedef cItemCallback cNoteBlockCallback;
typedef cItemCallback cCommandBlockCallback;
typedef cItemCallback cMobHeadCallback;
typedef cItemCallback cFlowerPotCallback;
+typedef cItemCallback cRedstonePoweredCallback;
@@ -237,7 +239,9 @@ public:
/** 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 */
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
-
+
+ /** Calls the callback for the redstone powered entity at the specified coords; returns false if there's no redstone powered entity at those coords, true if found */
+ bool DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cRedstonePoweredCallback & a_Callback);
/** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp
index c1a2fcaae..5b2439db1 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator.cpp
@@ -3,11 +3,10 @@
#include "IncrementalRedstoneSimulator.h"
#include "BoundingBox.h"
-#include "../BlockEntities/DropSpenserEntity.h"
+#include "../BlockEntities/RedstonePoweredEntity.h"
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
-#include "../Entities/TNTEntity.h"
#include "../Entities/Pickup.h"
#include "../Blocks/BlockTorch.h"
#include "../Blocks/BlockDoor.h"
@@ -842,13 +841,13 @@ void cIncrementalRedstoneSimulator::HandlePiston(int a_RelBlockX, int a_RelBlock
void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ)
{
class cSetPowerToDropSpenser :
- public cDropSpenserCallback
+ public cRedstonePoweredCallback
{
bool m_IsPowered;
public:
cSetPowerToDropSpenser(bool a_IsPowered) : m_IsPowered(a_IsPowered) {}
- virtual bool Item(cDropSpenserEntity * a_DropSpenser) override
+ virtual bool Item(cRedstonePoweredEntity * a_DropSpenser) override
{
a_DropSpenser->SetRedstonePower(m_IsPowered);
return false;
@@ -857,7 +856,7 @@ void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_RelBlockX, int a_Rel
int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX;
int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ;
- m_Chunk->DoWithDropSpenserAt(BlockX, a_RelBlockY, BlockZ, DrSpSP);
+ m_Chunk->DoWithRedstonePoweredEntityAt(BlockX, a_RelBlockY, BlockZ, DrSpSP);
}
From 9272bd627c732771b81e6dcf6b8465404917a9d6 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Tue, 5 Aug 2014 22:54:36 +0100
Subject: [PATCH 110/751] Removed dependecy of redstone simulator on NoteBlock
---
src/BlockEntities/NoteEntity.h | 10 +++++++++-
src/BlockEntities/RedstonePoweredEntity.h | 4 ++++
src/Chunk.cpp | 1 +
src/Simulator/IncrementalRedstoneSimulator.cpp | 17 ++++++-----------
4 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h
index e8497da3e..f9db6cbe6 100644
--- a/src/BlockEntities/NoteEntity.h
+++ b/src/BlockEntities/NoteEntity.h
@@ -2,6 +2,7 @@
#pragma once
#include "BlockEntity.h"
+#include "RedstonePoweredEntity.h"
namespace Json
@@ -29,7 +30,8 @@ enum ENUM_NOTE_INSTRUMENTS
// tolua_begin
class cNoteEntity :
- public cBlockEntity
+ public cBlockEntity,
+ public cRedstonePoweredEntity
{
typedef cBlockEntity super;
public:
@@ -38,6 +40,7 @@ public:
/// Creates a new note entity. a_World may be NULL
cNoteEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
+ virtual ~cNoteEntity() {}
bool LoadFromJson(const Json::Value & a_Value);
virtual void SaveToJson(Json::Value & a_Value) override;
@@ -53,6 +56,11 @@ public:
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override {}
+
+ virtual void SetRedstonePower(bool a_Value)
+ {
+ if (a_Value) MakeSound();
+ }
static const char * GetClassStatic(void) { return "cNoteEntity"; }
diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h
index aebba771f..7d6904442 100644
--- a/src/BlockEntities/RedstonePoweredEntity.h
+++ b/src/BlockEntities/RedstonePoweredEntity.h
@@ -1,9 +1,13 @@
+#pragma once
// Interface class representing a blockEntity that responds to redstone
class cRedstonePoweredEntity
{
public:
+
+ virtual ~cRedstonePoweredEntity() {};
+
/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
virtual void SetRedstonePower(bool a_IsPowered) = 0;
};
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 9e06f58ec..1e8d0e6f0 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -2141,6 +2141,7 @@ bool cChunk::DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_Blo
{
case E_BLOCK_DROPPER:
case E_BLOCK_DISPENSER:
+ case E_BLOCK_NOTE_BLOCK:
break;
default:
// There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp
index 5b2439db1..7b3a2c2fa 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator.cpp
@@ -4,7 +4,6 @@
#include "IncrementalRedstoneSimulator.h"
#include "BoundingBox.h"
#include "../BlockEntities/RedstonePoweredEntity.h"
-#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../Entities/Pickup.h"
@@ -1033,25 +1032,21 @@ void cIncrementalRedstoneSimulator::HandleNoteBlock(int a_RelBlockX, int a_RelBl
if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true))
{
class cSetPowerToNoteBlock :
- public cNoteBlockCallback
+ public cRedstonePoweredCallback
{
- bool m_IsPowered;
public:
- cSetPowerToNoteBlock(bool a_IsPowered) : m_IsPowered(a_IsPowered) {}
+ cSetPowerToNoteBlock() {}
- virtual bool Item(cNoteEntity * a_NoteBlock) override
+ virtual bool Item(cRedstonePoweredEntity * a_NoteBlock) override
{
- if (m_IsPowered)
- {
- a_NoteBlock->MakeSound();
- }
+ a_NoteBlock->SetRedstonePower(true);
return false;
}
- } NoteBlockSP(m_bAreCoordsPowered);
+ } NoteBlockSP;
int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX;
int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ;
- m_Chunk->DoWithNoteBlockAt(BlockX, a_RelBlockY, BlockZ, NoteBlockSP);
+ m_Chunk->DoWithRedstonePoweredEntityAt(BlockX, a_RelBlockY, BlockZ, NoteBlockSP);
SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true);
}
}
From ff7171fc5a567590dd52d4213439778f0dfcce53 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 6 Aug 2014 14:04:25 +0200
Subject: [PATCH 111/751] Resending fire to the client when the interact
cancelled.
---
src/ClientHandle.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 72257028a..3e046f38d 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -920,6 +920,10 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
)
{
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))->IsClickedThrough())
+ {
+ m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player);
+ }
return;
}
@@ -928,6 +932,10 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
{
// A plugin doesn't agree with the action, replace the block on the client and quit:
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))->IsClickedThrough())
+ {
+ m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player);
+ }
return;
}
From a0ba7426c6bc2059d5db6d248ef8e582e40ce4b3 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 6 Aug 2014 13:17:05 +0100
Subject: [PATCH 112/751] Fixed multiple inhertance being output by tolua
---
src/BlockEntities/DropSpenserEntity.h | 10 ++++++----
src/BlockEntities/NoteEntity.h | 6 ++++--
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h
index dabe9a27b..be56447aa 100644
--- a/src/BlockEntities/DropSpenserEntity.h
+++ b/src/BlockEntities/DropSpenserEntity.h
@@ -30,8 +30,10 @@ class cServer;
// tolua_begin
class cDropSpenserEntity :
- public cBlockEntityWithItems,
- public cRedstonePoweredEntity
+ public cBlockEntityWithItems
+ // tolua_end
+ , public cRedstonePoweredEntity
+ // tolua_begin
{
typedef cBlockEntityWithItems super;
@@ -65,10 +67,10 @@ public:
/// Sets the dropspenser to dropspense an item in the next tick
void Activate(void);
+ // tolua_end
+
/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
virtual void SetRedstonePower(bool a_IsPowered) override;
-
- // tolua_end
protected:
bool m_ShouldDropSpense; ///< If true, the dropspenser will dropspense an item in the next tick
diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h
index f9db6cbe6..dd201e0a9 100644
--- a/src/BlockEntities/NoteEntity.h
+++ b/src/BlockEntities/NoteEntity.h
@@ -30,8 +30,10 @@ enum ENUM_NOTE_INSTRUMENTS
// tolua_begin
class cNoteEntity :
- public cBlockEntity,
- public cRedstonePoweredEntity
+ public cBlockEntity
+ // tolua_end
+ , public cRedstonePoweredEntity
+ // tolua_begin
{
typedef cBlockEntity super;
public:
From 6acddd0cad25078ae2c67e7a0eb353e9d4d100e2 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 6 Aug 2014 13:19:22 +0100
Subject: [PATCH 113/751] Fixed style issues
---
src/BlockEntities/NoteEntity.h | 5 ++++-
src/BlockEntities/RedstonePoweredEntity.h | 2 +-
src/Chunk.cpp | 6 +++---
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h
index dd201e0a9..f538de060 100644
--- a/src/BlockEntities/NoteEntity.h
+++ b/src/BlockEntities/NoteEntity.h
@@ -61,7 +61,10 @@ public:
virtual void SetRedstonePower(bool a_Value)
{
- if (a_Value) MakeSound();
+ if (a_Value)
+ {
+ MakeSound();
+ }
}
static const char * GetClassStatic(void) { return "cNoteEntity"; }
diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h
index 7d6904442..f11df4fc4 100644
--- a/src/BlockEntities/RedstonePoweredEntity.h
+++ b/src/BlockEntities/RedstonePoweredEntity.h
@@ -8,6 +8,6 @@ public:
virtual ~cRedstonePoweredEntity() {};
-/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
+ /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
virtual void SetRedstonePower(bool a_IsPowered) = 0;
};
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 1e8d0e6f0..a79a485a6 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -2142,10 +2142,10 @@ bool cChunk::DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_Blo
case E_BLOCK_DROPPER:
case E_BLOCK_DISPENSER:
case E_BLOCK_NOTE_BLOCK:
- break;
+ break;
default:
- // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out
- return false;
+ // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out
+ return false;
}
if (a_Callback.Item((cRedstonePoweredEntity *)*itr))
From beab61bbfeca0280bce941c4175837109282c828 Mon Sep 17 00:00:00 2001
From: archshift
Date: Wed, 6 Aug 2014 14:16:36 -0700
Subject: [PATCH 114/751] On destroy ender crystal, create bedrock and fire
---
src/Entities/EnderCrystal.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/Entities/EnderCrystal.cpp b/src/Entities/EnderCrystal.cpp
index bf86a6c42..c17bb608e 100644
--- a/src/Entities/EnderCrystal.cpp
+++ b/src/Entities/EnderCrystal.cpp
@@ -32,9 +32,6 @@ void cEnderCrystal::SpawnOn(cClientHandle & a_ClientHandle)
void cEnderCrystal::Tick(float a_Dt, cChunk & a_Chunk)
{
UNUSED(a_Dt);
-
- a_Chunk.SetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT, E_BLOCK_FIRE, 0);
-
// No further processing (physics e.t.c.) is needed
}
@@ -49,6 +46,9 @@ void cEnderCrystal::KilledBy(TakeDamageInfo & a_TDI)
m_World->DoExplosionAt(6.0, GetPosX(), GetPosY(), GetPosZ(), true, esEnderCrystal, this);
Destroy();
+
+ m_World->SetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT, E_BLOCK_BEDROCK, 0);
+ m_World->SetBlock(POSX_TOINT, POSY_TOINT + 1, POSZ_TOINT, E_BLOCK_FIRE, 0);
}
From 4271d719b68521f91770574b3064525512116670 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 7 Aug 2014 01:07:32 +0200
Subject: [PATCH 115/751] Added SetDoDaylightCycle() and
IsDaylightCycleEnabled() to cWorld. I need this for a GameRule plugin.
---
src/ClientHandle.cpp | 11 ++++++++-
src/ClientHandle.h | 2 +-
src/World.cpp | 53 ++++++++++++++++++++++++++++----------------
src/World.h | 14 +++++++++++-
4 files changed, 58 insertions(+), 22 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 3e046f38d..286c17513 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -342,7 +342,16 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
}
// Send time
- m_Protocol->SendTimeUpdate(World->GetWorldAge(), World->GetTimeOfDay());
+ Int64 TimeOfDay = World->GetTimeOfDay();
+ if (!World->IsDaylightCycleEnabled())
+ {
+ TimeOfDay *= -1;
+ if (TimeOfDay == 0)
+ {
+ TimeOfDay = -1;
+ }
+ }
+ m_Protocol->SendTimeUpdate(World->GetWorldAge(), TimeOfDay);
// Send contents of the inventory window
m_Protocol->SendWholeInventory(*m_Player->GetWindow());
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index ee1db3155..1bf397ad2 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -179,7 +179,7 @@ public:
void SendTabCompletionResults(const AStringVector & a_Results);
void SendTeleportEntity (const cEntity & a_Entity);
void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
- void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay);
+ void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay); // tolua_export
void SendUnloadChunk (int a_ChunkX, int a_ChunkZ);
void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity);
void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
diff --git a/src/World.cpp b/src/World.cpp
index d2213d1e5..7ed8bc1e4 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -243,6 +243,7 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
#endif
m_Dimension(a_Dimension),
m_IsSpawnExplicitlySet(false),
+ m_DoDaylightCycle(true),
m_WorldAgeSecs(0),
m_TimeOfDaySecs(0),
m_WorldAge(0),
@@ -827,28 +828,32 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
{
SetChunkData(**itr);
} // for itr - SetChunkDataQueue[]
-
- // We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
+
m_WorldAgeSecs += (double)a_Dt / 1000.0;
- m_TimeOfDaySecs += (double)a_Dt / 1000.0;
-
- // Wrap time of day each 20 minutes (1200 seconds)
- if (m_TimeOfDaySecs > 1200.0)
- {
- m_TimeOfDaySecs -= 1200.0;
- }
-
m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0);
- m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0);
- // Updates the sky darkness based on current time of day
- UpdateSkyDarkness();
-
- // Broadcast time update every 40 ticks (2 seconds)
- if (m_LastTimeUpdate < m_WorldAge - 40)
+ if (m_DoDaylightCycle)
{
- BroadcastTimeUpdate();
- m_LastTimeUpdate = m_WorldAge;
+ // We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
+ m_TimeOfDaySecs += (double)a_Dt / 1000.0;
+
+ // Wrap time of day each 20 minutes (1200 seconds)
+ if (m_TimeOfDaySecs > 1200.0)
+ {
+ m_TimeOfDaySecs -= 1200.0;
+ }
+
+ m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0);
+
+ // Updates the sky darkness based on current time of day
+ UpdateSkyDarkness();
+
+ // Broadcast time update every 40 ticks (2 seconds)
+ if (m_LastTimeUpdate < m_WorldAge - 40)
+ {
+ BroadcastTimeUpdate();
+ m_LastTimeUpdate = m_WorldAge;
+ }
}
// Add entities waiting in the queue to be added:
@@ -2243,6 +2248,16 @@ void cWorld::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, cons
void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
{
+ int TimeOfDay = m_TimeOfDay;
+ if (!m_DoDaylightCycle)
+ {
+ TimeOfDay *= -1;
+ if (TimeOfDay == 0)
+ {
+ TimeOfDay = -1;
+ }
+ }
+
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
@@ -2251,7 +2266,7 @@ void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
{
continue;
}
- ch->SendTimeUpdate(m_WorldAge, m_TimeOfDay);
+ ch->SendTimeUpdate(m_WorldAge, TimeOfDay);
}
}
diff --git a/src/World.h b/src/World.h
index 90b798e8e..8ddc69118 100644
--- a/src/World.h
+++ b/src/World.h
@@ -145,7 +145,17 @@ public:
// tolua_begin
int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; }
-
+
+ /** Is the daylight cyclus enabled? */
+ virtual bool IsDaylightCycleEnabled(void) const { return m_DoDaylightCycle; }
+
+ /** Sets the daylight cyclus to true/false. */
+ virtual void SetDoDaylightCycle(bool a_DoDaylightCycle)
+ {
+ m_DoDaylightCycle = a_DoDaylightCycle;
+ BroadcastTimeUpdate();
+ }
+
virtual Int64 GetWorldAge (void) const override { return m_WorldAge; }
virtual Int64 GetTimeOfDay(void) const override { return m_TimeOfDay; }
@@ -158,6 +168,7 @@ public:
{
m_TimeOfDay = a_TimeOfDay;
m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0;
+ UpdateSkyDarkness();
BroadcastTimeUpdate();
}
@@ -868,6 +879,7 @@ private:
bool m_BroadcastDeathMessages;
bool m_BroadcastAchievementMessages;
+ bool m_DoDaylightCycle; // Is the daylight cyclus enabled?
double m_WorldAgeSecs; // World age, in seconds. Is only incremented, cannot be set by plugins.
double m_TimeOfDaySecs; // Time of day in seconds. Can be adjusted. Is wrapped to zero each day.
Int64 m_WorldAge; // World age in ticks, calculated off of m_WorldAgeSecs
From 0c622522ea52ed07aa12a25827b498acd290b531 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 7 Aug 2014 01:08:31 +0200
Subject: [PATCH 116/751] Removed debug message.
---
src/Bindings/ManualBindings.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 9ba1501c5..8e6156d97 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -507,7 +507,6 @@ static int tolua_DoWithXYZ(lua_State* tolua_S)
int ItemX = ((int)tolua_tonumber(tolua_S, 2, 0));
int ItemY = ((int)tolua_tonumber(tolua_S, 3, 0));
int ItemZ = ((int)tolua_tonumber(tolua_S, 4, 0));
- LOG("x %i y %i z %i", ItemX, ItemY, ItemZ);
if (!lua_isfunction( tolua_S, 5))
{
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #4");
From a73c85d7eb8181b3792f19675c29f43bd8c0b738 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 7 Aug 2014 02:42:42 +0200
Subject: [PATCH 117/751] Fixed nether wart digging. Fixes #1265
---
src/BlockInfo.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 4bc3fbbdc..a59229f87 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -294,6 +294,7 @@ void cBlockInfo::Initialize(cBlockInfoArray & a_Info)
a_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_OneHitDig = true;
a_Info[E_BLOCK_LILY_PAD ].m_OneHitDig = true;
a_Info[E_BLOCK_MELON_STEM ].m_OneHitDig = true;
+ a_Info[E_BLOCK_NETHER_WART ].m_OneHitDig = true;
a_Info[E_BLOCK_POTATOES ].m_OneHitDig = true;
a_Info[E_BLOCK_PUMPKIN_STEM ].m_OneHitDig = true;
a_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_OneHitDig = true;
From 670e94bfeb62a51ca64ffaa0e45086e1ca91057c Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 8 Aug 2014 09:56:28 +0200
Subject: [PATCH 118/751] RankMgr: Renamed PermissionGroup to Group in API and
PermGroup in DB.
"Group" is SQL keyword and shouldn't be used as table name.
---
src/RankManager.cpp | 26 +++++++++++++-------------
src/RankManager.h | 38 +++++++++++++++++++++++---------------
2 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index 18ed65b26..e77fb22b9 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -13,7 +13,7 @@
-/*
+//*
// This code is for internal testing while developing the cRankManager class
static class cRankMgrTest
{
@@ -38,7 +38,7 @@ public:
std::cout << " Rank: '" << m_Mgr.GetPlayerRankName(UUID) << "'." << std::endl;
// List all the permission groups for the player:
- AStringVector Groups = m_Mgr.GetPlayerPermissionGroups(UUID);
+ AStringVector Groups = m_Mgr.GetPlayerGroups(UUID);
std::cout << " Groups(" << Groups.size() << "):" << std::endl;
for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
{
@@ -72,9 +72,9 @@ cRankManager::cRankManager(void) :
// Create the DB tables, if they don't exist:
m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID INTEGER PRIMARY KEY, Name, MsgPrefix, MsgPostfix, MsgNameColorCode)");
m_DB.exec("CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID INTEGER)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionGroup (GroupID INTEGER PRIMARY KEY, Name)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermissionGroups (RankID INTEGER, GroupID INTEGER)");
- m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (GroupID INTEGER, Permission)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PermGroup (PermGroupID INTEGER PRIMARY KEY, Name)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermGroup (RankID INTEGER, PermGroupID INTEGER)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (PermGroupID INTEGER, Permission)");
// TODO: Check if tables empty, add some defaults then
}
@@ -100,15 +100,15 @@ AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
-AStringVector cRankManager::GetPlayerPermissionGroups(const AString & a_PlayerUUID)
+AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
{
// Prepare the DB statement:
SQLite::Statement stmt(m_DB,
- "SELECT PermissionGroup.Name FROM PermissionGroup "
- "LEFT JOIN RankPermissionGroups "
- "ON PermissionGroup.GroupID = RankPermissionGroups.GroupID "
+ "SELECT Group.Name FROM Group "
+ "LEFT JOIN RankGroups "
+ "ON Group.GroupID = RankGroups.GroupID "
"LEFT JOIN PlayerRank "
- "ON PlayerRank.RankID = RankPermissionGroups.RankID "
+ "ON PlayerRank.RankID = RankGroups.RankID "
"WHERE PlayerRank.PlayerUUID = ?"
);
stmt.bind(1, a_PlayerUUID);
@@ -131,10 +131,10 @@ AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
// Prepare the DB statement:
SQLite::Statement stmt(m_DB,
"SELECT PermissionItem.Permission FROM PermissionItem "
- "LEFT JOIN RankPermissionGroups "
- "ON PermissionItem.GroupID = RankPermissionGroups.GroupID "
+ "LEFT JOIN RankGroups "
+ "ON PermissionItem.GroupID = RankGroups.GroupID "
"LEFT JOIN PlayerRank "
- "ON PlayerRank.RankID = RankPermissionGroups.RankID "
+ "ON PlayerRank.RankID = RankGroups.RankID "
"WHERE PlayerRank.PlayerUUID = ?"
);
stmt.bind(1, a_PlayerUUID);
diff --git a/src/RankManager.h b/src/RankManager.h
index 1eaeb97a1..0b1db2fb8 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -22,23 +22,26 @@ public:
/** Returns the name of the rank that the specified player has assigned to them. */
AString GetPlayerRankName(const AString & a_PlayerUUID);
- /** Returns the names of PermissionGroups that the specified player has assigned to them. */
- AStringVector GetPlayerPermissionGroups(const AString & a_PlayerUUID);
+ /** Returns the names of Groups that the specified player has assigned to them. */
+ AStringVector GetPlayerGroups(const AString & a_PlayerUUID);
/** Returns the permissions that the specified player has assigned to them. */
AStringVector GetPlayerPermissions(const AString & a_PlayerUUID);
/** Returns the names of groups that the specified rank has assigned to it. */
- AStringVector GetRankPermissionGroups(const AString & a_RankName);
+ AStringVector GetRankGroups(const AString & a_RankName);
- /** Returns the permissions that the specified permission group has assigned to it. */
- AStringVector GetPermissionGroupPermissiont(const AString & a_GroupName);
+ /** Returns the permissions that the specified group has assigned to it. */
+ AStringVector GetGroupPermissions(const AString & a_GroupName);
+
+ /** Returns all permissions that the specified rank has assigned to it, through all its groups. */
+ AStringVector GetRankPermissions(const AString & a_RankName);
/** Returns the names of all defined ranks. */
AStringVector GetAllRanks(void);
/** Returns the names of all permission groups. */
- AStringVector GetAllPermissionGroups(void);
+ AStringVector GetAllGroups(void);
/** Returns all the distinct permissions that are stored in the DB. */
AStringVector GetAllPermissions(void);
@@ -60,37 +63,42 @@ public:
);
/** Adds a new permission group. No action if such a group already exists. */
- void AddPermissionGroup(const AString & a_GroupName);
+ void AddGroup(const AString & a_GroupName);
/** Adds the specified permission group to the specified rank.
Fails if the rank or group names are not found.
Returns true if successful, false on error. */
- bool AddPermissionGroupToRank(const AString & a_RankName, const AString & a_GroupName);
+ bool AddGroupToRank(const AString & a_RankName, const AString & a_GroupName);
/** Adds the specified permission to the specified permission group.
Fails if the permission group name is not found.
Returns true if successful, false on error. */
- bool AddPermissionToPermissionGroup(const AString & a_Permission, const AString & a_GroupName);
+ bool AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName);
/** Removes the specified rank.
All players assigned to that rank will be re-assigned to a_ReplacementRankName, unless it is empty. */
void RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName);
- /** Removes the specified permission group. */
- void RemovePermissionGroup(const AString & a_PermissionGroup);
+ /** Removes the specified group completely.
+ The group will first be removed from all ranks using it, and then removed itself. */
+ void RemoveGroup(const AString & a_GroupName);
- /** Removes the specified permission from the specified permission group. */
- void RemovePermission(const AString & a_Permission, const AString & a_PermissionGroup);
+ /** Removes the specified group from the specified rank.
+ The group will stay defined, even if no rank is using it. */
+ void RemoveGroupFromRank(const AString & a_RankName, const AString & a_GroupName);
+
+ /** Removes the specified permission from the specified group. */
+ void RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName);
/** Renames the specified rank. No action if the rank name is not found.
Fails if the new name is already used.
Returns true on success, false on failure. */
bool RenameRank(const AString & a_OldName, const AString & a_NewName);
- /** Renames the specified permission group. No action if the rank name is not found.
+ /** Renames the specified group. No action if the rank name is not found.
Fails if the new name is already used.
Returns true on success, false on failure. */
- bool RenamePermissionGroup(const AString & a_OldName, const AString & a_NewName);
+ bool RenameGroup(const AString & a_OldName, const AString & a_NewName);
/** Sets the specified player's rank.
If the player already had rank assigned to them, it is overwritten with the new rank.
From 65b81b4ab7f580c98ca80b8e57a13de961f19131 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 8 Aug 2014 10:02:25 +0200
Subject: [PATCH 119/751] RankMgr: Implemented the basic API functions.
---
src/RankManager.cpp | 738 ++++++++++++++++++++++++++++++++++++++++----
src/RankManager.h | 18 +-
2 files changed, 696 insertions(+), 60 deletions(-)
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index e77fb22b9..e02e63a24 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -5,15 +5,13 @@
#include "Globals.h"
#include "RankManager.h"
-#include "Protocol/MojangAPI.h"
-#include "inifile/iniFile.h"
-#include
+#include "SQLiteCpp/Transaction.h"
-//*
+/*
// This code is for internal testing while developing the cRankManager class
static class cRankMgrTest
{
@@ -21,44 +19,72 @@ public:
cRankMgrTest(void) :
m_Mgr()
{
- // Initialize the cMojangAPI so that it can convert playernames to UUIDs:
- cIniFile Ini;
- Ini.ReadFile("settings.ini");
- m_API.Start(Ini);
+ // Initialize logging:
+ new cMCLogger();
+ AString UUID = "b1caf24202a841a78055a079c460eee7"; // UUID for "xoft"
+ LOG("Testing UUID %s", UUID.c_str());
- // Test the cRankManager class:
- ReportPlayer("xoft");
+ // Test the initial state of the ranks:
+ LOG("Initial test:");
+ ReportPlayer(UUID);
+
+ // Add a rank, a few groups and permissions and set the player to use them:
+ LOG("Adding data...");
+ m_Mgr.AddRank("TestRank", "[test]", "[/test]", "7");
+ m_Mgr.AddGroup("TestGroup1");
+ m_Mgr.AddGroup("TestGroup2");
+ m_Mgr.AddGroupToRank("TestGroup1", "TestRank");
+ m_Mgr.AddGroupToRank("TestGroup2", "TestRank");
+ m_Mgr.AddPermissionToGroup("testpermission1.1", "TestGroup1");
+ m_Mgr.AddPermissionToGroup("testpermission1.2", "TestGroup1");
+ m_Mgr.AddPermissionToGroup("testpermission2.1", "TestGroup2");
+ m_Mgr.SetPlayerRank(UUID, "TestRank");
+
+ // Test the added data:
+ LOG("Testing the added data:");
+ LOG("IsGroupInRank(TestGroup1, TestRank) = %s", m_Mgr.IsGroupInRank("TestGroup1", "TestRank") ? "true" : "false");
+ LOG("IsGroupInRank(TestGroup3, TestRank) = %s", m_Mgr.IsGroupInRank("TestGroup3", "TestRank") ? "true" : "false");
+ LOG("IsPermissionInGroup(testpermission1.2, TestGroup1) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup1") ? "true" : "false");
+ LOG("IsPermissionInGroup(testpermission1.2, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup2") ? "true" : "false");
+ LOG("IsPermissionInGroup(testpermission1.3, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.3", "TestGroup2") ? "true" : "false");
+ LOG("IsPlayerRankSet(%s) = %s", UUID.c_str(), m_Mgr.IsPlayerRankSet(UUID) ? "true" : "false");
+ LOG("IsPlayerRankSet(%s1) = %s", UUID.c_str(), m_Mgr.IsPlayerRankSet(UUID + "1") ? "true" : "false");
+ LOG("GroupExists(TestGroup1) = %s", m_Mgr.GroupExists("TestGroup1") ? "true" : "false");
+ LOG("GroupExists(TestGroup3) = %s", m_Mgr.GroupExists("TestGroup3") ? "true" : "false");
+ LOG("RankExists(TestRank) = %s", m_Mgr.RankExists("TestRank") ? "true" : "false");
+ LOG("RankExists(NonexistentRank) = %s", m_Mgr.RankExists("NonexistentRank") ? "true" : "false");
+
+ // Test the assignments above:
+ LOG("After-assignment test:");
+ ReportPlayer(UUID);
+
+ LOG("Done.");
}
- void ReportPlayer(const AString & a_PlayerName)
+ void ReportPlayer(const AString & a_PlayerUUID)
{
// Get the player's UUID and rank:
- AString UUID = m_API.GetUUIDFromPlayerName(a_PlayerName);
- std::cout << "Player " << a_PlayerName << " has UUID '" << UUID <<"'." << std::endl;
- std::cout << " Rank: '" << m_Mgr.GetPlayerRankName(UUID) << "'." << std::endl;
+ LOG(" Rank: '%s'", m_Mgr.GetPlayerRankName(a_PlayerUUID).c_str());
// List all the permission groups for the player:
- AStringVector Groups = m_Mgr.GetPlayerGroups(UUID);
- std::cout << " Groups(" << Groups.size() << "):" << std::endl;
+ AStringVector Groups = m_Mgr.GetPlayerGroups(a_PlayerUUID);
+ LOG(" Groups(%u):", (unsigned)Groups.size());
for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
{
- std::cout << " '" << *itr << "'." << std::endl;
+ LOG(" '%s'" , itr->c_str());
} // for itr - Groups[]
// List all the permissions for the player:
- AStringVector Permissions = m_Mgr.GetPlayerPermissions(UUID);
- std::cout << " Permissions(" << Permissions.size() << "):" << std::endl;
+ AStringVector Permissions = m_Mgr.GetPlayerPermissions(a_PlayerUUID);
+ LOG(" Permissions(%u):", (unsigned)Permissions.size());
for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
{
- std::cout << " '" << *itr << "'." << std::endl;
+ LOG(" '%s'", itr->c_str());
} // for itr - Groups[]
-
- std::cout << "Done." << std::endl;
}
protected:
cRankManager m_Mgr;
- cMojangAPI m_API;
} g_RankMgrTest;
//*/
@@ -70,7 +96,7 @@ cRankManager::cRankManager(void) :
m_DB("Ranks.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)
{
// Create the DB tables, if they don't exist:
- m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID INTEGER PRIMARY KEY, Name, MsgPrefix, MsgPostfix, MsgNameColorCode)");
+ m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID INTEGER PRIMARY KEY, Name, MsgPrefix, MsgSuffix, MsgNameColorCode)");
m_DB.exec("CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID INTEGER)");
m_DB.exec("CREATE TABLE IF NOT EXISTS PermGroup (PermGroupID INTEGER PRIMARY KEY, Name)");
m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermGroup (RankID INTEGER, PermGroupID INTEGER)");
@@ -85,15 +111,23 @@ cRankManager::cRankManager(void) :
AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
{
- SQLite::Statement stmt(m_DB, "SELECT Rank.Name FROM Rank LEFT JOIN PlayerRank ON Rank.RankID = PlayerRank.RankID WHERE PlayerRank.PlayerUUID = ?");
- stmt.bind(1, a_PlayerUUID);
- stmt.executeStep();
- if (stmt.isDone())
+ try
{
- // No data returned from the DB
- return AString();
+ SQLite::Statement stmt(m_DB, "SELECT Rank.Name FROM Rank LEFT JOIN PlayerRank ON Rank.RankID = PlayerRank.RankID WHERE PlayerRank.PlayerUUID = ?");
+ stmt.bind(1, a_PlayerUUID);
+ stmt.executeStep();
+ if (stmt.isDone())
+ {
+ // No data returned from the DB
+ return AString();
+ }
+ return stmt.getColumn(0).getText();
}
- return stmt.getColumn(0).getText();
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Cannot get player rank name: %s", __FUNCTION__, ex.what());
+ }
+ return AString();
}
@@ -102,22 +136,29 @@ AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
{
- // Prepare the DB statement:
- SQLite::Statement stmt(m_DB,
- "SELECT Group.Name FROM Group "
- "LEFT JOIN RankGroups "
- "ON Group.GroupID = RankGroups.GroupID "
- "LEFT JOIN PlayerRank "
- "ON PlayerRank.RankID = RankGroups.RankID "
- "WHERE PlayerRank.PlayerUUID = ?"
- );
- stmt.bind(1, a_PlayerUUID);
-
- // Execute and get results:
AStringVector res;
- while (stmt.executeStep())
+ try
{
- res.push_back(stmt.getColumn(0).getText());
+ // Prepare the DB statement:
+ SQLite::Statement stmt(m_DB,
+ "SELECT PermGroup.Name FROM PermGroup "
+ "LEFT JOIN RankPermGroup "
+ "ON PermGroup.PermGroupID = RankPermGroup.PermGroupID "
+ "LEFT JOIN PlayerRank "
+ "ON PlayerRank.RankID = RankPermGroup.RankID "
+ "WHERE PlayerRank.PlayerUUID = ?"
+ );
+ stmt.bind(1, a_PlayerUUID);
+
+ // Execute and get results:
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Cannot get player groups: %s", __FUNCTION__, ex.what());
}
return res;
}
@@ -128,22 +169,29 @@ AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
{
- // Prepare the DB statement:
- SQLite::Statement stmt(m_DB,
- "SELECT PermissionItem.Permission FROM PermissionItem "
- "LEFT JOIN RankGroups "
- "ON PermissionItem.GroupID = RankGroups.GroupID "
- "LEFT JOIN PlayerRank "
- "ON PlayerRank.RankID = RankGroups.RankID "
- "WHERE PlayerRank.PlayerUUID = ?"
- );
- stmt.bind(1, a_PlayerUUID);
-
- // Execute and get results:
AStringVector res;
- while (stmt.executeStep())
+ try
{
- res.push_back(stmt.getColumn(0).getText());
+ // Prepare the DB statement:
+ SQLite::Statement stmt(m_DB,
+ "SELECT PermissionItem.Permission FROM PermissionItem "
+ "LEFT JOIN RankPermGroup "
+ "ON PermissionItem.PermGroupID = RankPermGroup.PermGroupID "
+ "LEFT JOIN PlayerRank "
+ "ON PlayerRank.RankID = RankPermGroup.RankID "
+ "WHERE PlayerRank.PlayerUUID = ?"
+ );
+ stmt.bind(1, a_PlayerUUID);
+
+ // Execute and get results:
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Cannot get player permissions: %s", __FUNCTION__, ex.what());
}
return res;
}
@@ -151,3 +199,575 @@ AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
+
+AStringVector cRankManager::GetRankGroups(const AString & a_RankName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ AStringVector res;
+ res.push_back(Printf("%s: DummyGroup", __FUNCTION__));
+ return res;
+}
+
+
+
+
+
+AStringVector cRankManager::GetGroupPermissions(const AString & a_GroupName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ AStringVector res;
+ res.push_back(Printf("%s: DummyPermission", __FUNCTION__));
+ return res;
+}
+
+
+
+
+
+AStringVector cRankManager::GetRankPermissions(const AString & a_RankName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ AStringVector res;
+ res.push_back(Printf("%s: DummyPermission", __FUNCTION__));
+ return res;
+}
+
+
+
+
+
+AStringVector cRankManager::GetAllRanks(void)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ AStringVector res;
+ res.push_back(Printf("%s: DummyRank", __FUNCTION__));
+ return res;
+}
+
+
+
+
+
+AStringVector cRankManager::GetAllGroups(void)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ AStringVector res;
+ res.push_back(Printf("%s: DummyGroup", __FUNCTION__));
+ return res;
+}
+
+
+
+
+
+AStringVector cRankManager::GetAllPermissions(void)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ AStringVector res;
+ res.push_back(Printf("%s: DummyPermission", __FUNCTION__));
+ return res;
+}
+
+
+
+
+
+void cRankManager::GetPlayerMsgVisuals(
+ const AString & a_PlayerUUID,
+ AString & a_MsgPrefix,
+ AString & a_MsgSuffix,
+ AString & a_MsgNameColorCode
+)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ a_MsgPrefix = Printf("%s: DummyPrefix", __FUNCTION__);
+ a_MsgSuffix = Printf("%s: DummySuffix", __FUNCTION__);
+ a_MsgNameColorCode = Printf("%s: DummyMsgNameColorCode", __FUNCTION__);
+}
+
+
+
+
+
+void cRankManager::AddRank(
+ const AString & a_RankName,
+ const AString & a_MsgPrefix,
+ const AString & a_MsgSuffix,
+ const AString & a_MsgNameColorCode
+)
+{
+ try
+ {
+ // Check if such a rank name is already used:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM Rank WHERE Name = ?");
+ stmt.bind(1, a_RankName);
+ if (stmt.executeStep())
+ {
+ if (stmt.getColumn(0).getInt() > 0)
+ {
+ // Rank already exists, do nothing:
+ return;
+ }
+ }
+ }
+
+ // Insert a new rank:
+ SQLite::Statement stmt(m_DB, "INSERT INTO Rank (Name, MsgPrefix, MsgSuffix, MsgNameColorCode) VALUES (?, ?, ?, ?)");
+ stmt.bind(1, a_RankName);
+ stmt.bind(2, a_MsgPrefix);
+ stmt.bind(3, a_MsgSuffix);
+ stmt.bind(4, a_MsgNameColorCode);
+ if (stmt.exec() <= 0)
+ {
+ LOGWARNING("%s: Failed to add a new rank \"%s\".", __FUNCTION__, a_RankName.c_str());
+ return;
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to add a new rank \"%s\": %s", __FUNCTION__, a_RankName.c_str(), ex.what());
+ }
+}
+
+
+
+
+
+void cRankManager::AddGroup(const AString & a_GroupName)
+{
+ try
+ {
+ // Check if such a rank name is already used:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, a_GroupName);
+ if (stmt.executeStep())
+ {
+ if (stmt.getColumn(0).getInt() > 0)
+ {
+ // Group already exists, do nothing:
+ return;
+ }
+ }
+ }
+
+ // Insert a new rank:
+ SQLite::Statement stmt(m_DB, "INSERT INTO PermGroup (Name) VALUES (?)");
+ stmt.bind(1, a_GroupName);
+ if (stmt.exec() <= 0)
+ {
+ LOGWARNING("%s: Failed to add a new group \"%s\".", __FUNCTION__, a_GroupName.c_str());
+ return;
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to add a new group \"%s\": %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
+ }
+}
+
+
+
+
+
+bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a_RankName)
+{
+ try
+ {
+ SQLite::Transaction trans(m_DB);
+ int GroupID, RankID;
+
+ // Get the group's ID:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, a_GroupName);
+ if (!stmt.executeStep())
+ {
+ LOGWARNING("%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
+ return false;
+ }
+ GroupID = stmt.getColumn(0);
+ }
+
+ // Get the rank's ID:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
+ stmt.bind(1, a_RankName);
+ if (!stmt.executeStep())
+ {
+ LOGWARNING("%s: No such rank (%s), aborting.", __FUNCTION__, a_RankName.c_str());
+ return false;
+ }
+ RankID = stmt.getColumn(0);
+ }
+
+ // Check if the group is already there:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM RankPermGroup WHERE RankID = ? AND PermGroupID = ?");
+ stmt.bind(1, RankID);
+ stmt.bind(2, GroupID);
+ if (!stmt.executeStep())
+ {
+ LOGWARNING("%s: Failed to check binding between rank %s and group %s, aborting.", __FUNCTION__, a_RankName.c_str(), a_GroupName.c_str());
+ return false;
+ }
+ if (stmt.getColumn(0).getInt() > 0)
+ {
+ LOGD("%s: Group %s already present in rank %s, skipping and returning success.",
+ __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str()
+ );
+ return true;
+ }
+ }
+
+ // Add the group:
+ {
+ SQLite::Statement stmt(m_DB, "INSERT INTO RankPermGroup (RankID, PermGroupID) VALUES (?, ?)");
+ stmt.bind(1, RankID);
+ stmt.bind(2, GroupID);
+ if (stmt.exec() <= 0)
+ {
+ LOGWARNING("%s: Failed to add group %s to rank %s, aborting.", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str());
+ return false;
+ }
+ }
+
+ // Adding succeeded:
+ trans.commit();
+ return true;
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to add group %s to rank %s: %s", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str(), ex.what());
+ }
+ return false;
+}
+
+
+
+
+
+bool cRankManager::AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName)
+{
+ try
+ {
+ // Wrapp the entire operation into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Get the group's ID:
+ int GroupID;
+ {
+ SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, a_GroupName);
+ if (!stmt.executeStep())
+ {
+ LOGWARNING("%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
+ return false;
+ }
+ GroupID = stmt.getColumn(0).getInt();
+ }
+
+ // Check if the permission is already present:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
+ stmt.bind(1, GroupID);
+ stmt.bind(2, a_Permission);
+ if (!stmt.executeStep())
+ {
+ LOGWARNING("%s: Failed to check binding between permission %s and group %s, aborting.", __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str());
+ return false;
+ }
+ if (stmt.getColumn(0).getInt() > 0)
+ {
+ LOGD("%s: Permission %s is already present in group %s, skipping and returning success.",
+ __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str()
+ );
+ return true;
+ }
+ }
+
+ // Add the permission:
+ {
+ SQLite::Statement stmt(m_DB, "INSERT INTO PermissionItem (Permission, PermGroupID) VALUES (?, ?)");
+ stmt.bind(1, a_Permission);
+ stmt.bind(2, GroupID);
+ if (stmt.exec() <= 0)
+ {
+ LOGWARNING("%s: Failed to add permission %s to group %s, aborting.", __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str());
+ return false;
+ }
+ }
+
+ // Adding succeeded:
+ trans.commit();
+ return true;
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to add permission %s to group %s: %s",
+ __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str(), ex.what()
+ );
+ }
+ return false;
+}
+
+
+
+
+
+void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+}
+
+
+
+
+
+void cRankManager::RemoveGroup(const AString & a_GroupName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+}
+
+
+
+
+
+void cRankManager::RemoveGroupFromRank(const AString & a_RankName, const AString & a_GroupName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+}
+
+
+
+
+
+void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+}
+
+
+
+
+
+bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ return false;
+}
+
+
+
+
+
+bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewName)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ return false;
+}
+
+
+
+
+
+void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a_RankName)
+{
+ try
+ {
+ // Wrap the entire operation into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Get the rank ID:
+ int RankID;
+ {
+ SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
+ stmt.bind(1, a_RankName);
+ if (!stmt.executeStep())
+ {
+ LOGWARNING("%s: There is no rank %s, aborting.", __FUNCTION__, a_RankName.c_str());
+ return;
+ }
+ RankID = stmt.getColumn(0).getInt();
+ }
+
+ // Update the player's rank, if already in DB:
+ {
+ SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET RankID = ? WHERE PlayerUUID = ?");
+ stmt.bind(1, RankID);
+ stmt.bind(2, a_PlayerUUID);
+ if (stmt.exec() > 0)
+ {
+ // Successfully updated the player's rank
+ trans.commit();
+ return;
+ }
+ }
+
+ // The player is not yet in the DB, add them:
+ SQLite::Statement stmt(m_DB, "INSERT INTO PlayerRank (RankID, PlayerUUID) VALUES (?, ?)");
+ stmt.bind(1, RankID);
+ stmt.bind(2, a_PlayerUUID);
+ if (stmt.exec() > 0)
+ {
+ // Successfully added the player
+ trans.commit();
+ return;
+ }
+
+ LOGWARNING("%s: Failed to set player UUID %s to rank %s.",
+ __FUNCTION__, a_PlayerUUID.c_str(), a_RankName.c_str()
+ );
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to set player UUID %s to rank %s: %s",
+ __FUNCTION__, a_PlayerUUID.c_str(), a_RankName.c_str(), ex.what()
+ );
+ }
+}
+
+
+
+
+
+void cRankManager::SetRankVisuals(
+ const AString & a_RankName,
+ const AString & a_MsgPrefix,
+ const AString & a_MsgSuffix,
+ const AString & a_MsgNameColorCode
+)
+{
+ LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+}
+
+
+
+
+
+bool cRankManager::RankExists(const AString & a_RankName)
+{
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT * FROM Rank WHERE Name = ?");
+ stmt.bind(1, a_RankName);
+ if (stmt.executeStep())
+ {
+ // The rank was found
+ return true;
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to query DB for rank %s: %s", __FUNCTION__, a_RankName.c_str(), ex.what());
+ }
+ return false;
+}
+
+
+
+
+
+bool cRankManager::GroupExists(const AString & a_GroupName)
+{
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT * FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, a_GroupName);
+ if (stmt.executeStep())
+ {
+ // The group was found
+ return true;
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to query DB for group %s: %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
+ }
+ return false;
+}
+
+
+
+
+
+bool cRankManager::IsPlayerRankSet(const AString & a_PlayerUUID)
+{
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT * FROM PlayerRank WHERE PlayerUUID = ?");
+ stmt.bind(1, a_PlayerUUID);
+ if (stmt.executeStep())
+ {
+ // The player UUID was found, they have a rank
+ return true;
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to query DB for player UUID %s: %s", __FUNCTION__, a_PlayerUUID.c_str(), ex.what());
+ }
+ return false;
+}
+
+
+
+
+
+bool cRankManager::IsGroupInRank(const AString & a_GroupName, const AString & a_RankName)
+{
+ try
+ {
+ SQLite::Statement stmt(m_DB,
+ "SELECT * FROM Rank "
+ "LEFT JOIN RankPermGroup ON Rank.RankID = RankPermGroup.RankID "
+ "LEFT JOIN PermGroup ON PermGroup.PermGroupID = RankPermGroup.PermGroupID "
+ "WHERE Rank.Name = ? AND PermGroup.Name = ?"
+ );
+ stmt.bind(1, a_RankName);
+ stmt.bind(2, a_GroupName);
+ if (stmt.executeStep())
+ {
+ // The group is in the rank
+ return true;
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, ex.what());
+ }
+ return false;
+}
+
+
+
+
+
+bool cRankManager::IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName)
+{
+ try
+ {
+ SQLite::Statement stmt(m_DB,
+ "SELECT * FROM PermissionItem "
+ "LEFT JOIN PermGroup ON PermGroup.PermGroupID = PermissionItem.PermGroupID "
+ "WHERE PermissionItem.Permission = ? AND PermGroup.Name = ?"
+ );
+ stmt.bind(1, a_Permission);
+ stmt.bind(2, a_GroupName);
+ if (stmt.executeStep())
+ {
+ // The permission is in the group
+ return true;
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, ex.what());
+ }
+ return false;
+}
+
+
+
+
diff --git a/src/RankManager.h b/src/RankManager.h
index 0b1db2fb8..0c35b555f 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -68,7 +68,7 @@ public:
/** Adds the specified permission group to the specified rank.
Fails if the rank or group names are not found.
Returns true if successful, false on error. */
- bool AddGroupToRank(const AString & a_RankName, const AString & a_GroupName);
+ bool AddGroupToRank(const AString & a_GroupName, const AString & a_RankName);
/** Adds the specified permission to the specified permission group.
Fails if the permission group name is not found.
@@ -113,6 +113,22 @@ public:
const AString & a_MsgSuffix,
const AString & a_MsgNameColorCode
);
+
+ /** Returns true iff the specified rank exists in the DB. */
+ bool RankExists(const AString & a_RankName);
+
+ /** Returns true iff the specified group exists in the DB. */
+ bool GroupExists(const AString & a_GroupName);
+
+ /** Returns true iff the specified player has a rank assigned to them in the DB. */
+ bool IsPlayerRankSet(const AString & a_PlayerUUID);
+
+ /** Returns true iff the specified rank contains the specified group. */
+ bool IsGroupInRank(const AString & a_GroupName, const AString & a_RankName);
+
+ /** Returns true iff the specified group contains the specified permission. */
+ bool IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName);
+
protected:
SQLite::Database m_DB;
From a5b35e09ce1e352d4c57e66750a72335fc60d4b2 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 8 Aug 2014 16:38:38 +0200
Subject: [PATCH 120/751] RankMgr: Implemented GetXforY and GetAll APIs.
---
src/RankManager.cpp | 171 ++++++++++++++++++++++++++++++++++++++++----
src/RankManager.h | 9 ++-
2 files changed, 162 insertions(+), 18 deletions(-)
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index e02e63a24..ec9ac1b1d 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -11,7 +11,7 @@
-/*
+//*
// This code is for internal testing while developing the cRankManager class
static class cRankMgrTest
{
@@ -53,6 +53,13 @@ public:
LOG("GroupExists(TestGroup3) = %s", m_Mgr.GroupExists("TestGroup3") ? "true" : "false");
LOG("RankExists(TestRank) = %s", m_Mgr.RankExists("TestRank") ? "true" : "false");
LOG("RankExists(NonexistentRank) = %s", m_Mgr.RankExists("NonexistentRank") ? "true" : "false");
+ ReportRankGroups("TestRank");
+ ReportRankGroups("NonexistentRank");
+ ReportGroupPermissions("TestGroup1");
+ ReportGroupPermissions("NonexistentGroup");
+
+ // Report the contents of the DB:
+ ReportAll();
// Test the assignments above:
LOG("After-assignment test:");
@@ -61,6 +68,35 @@ public:
LOG("Done.");
}
+
+ void ReportAll(void)
+ {
+ // Report all ranks:
+ AStringVector Ranks = m_Mgr.GetAllRanks();
+ LOG("All ranks (%u):", (unsigned)Ranks.size());
+ for (AStringVector::const_iterator itr = Ranks.begin(), end = Ranks.end(); itr != end; ++itr)
+ {
+ LOG(" '%s'", itr->c_str());
+ }
+
+ // Report all groups:
+ AStringVector Groups = m_Mgr.GetAllGroups();
+ LOG("All groups (%u):", (unsigned)Groups.size());
+ for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
+ {
+ LOG(" '%s'", itr->c_str());
+ }
+
+ // Report all permissions:
+ AStringVector Permissions = m_Mgr.GetAllPermissions();
+ LOG("All permissions (%u):", (unsigned)Permissions.size());
+ for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
+ {
+ LOG(" '%s'", itr->c_str());
+ }
+ }
+
+
void ReportPlayer(const AString & a_PlayerUUID)
{
// Get the player's UUID and rank:
@@ -68,7 +104,7 @@ public:
// List all the permission groups for the player:
AStringVector Groups = m_Mgr.GetPlayerGroups(a_PlayerUUID);
- LOG(" Groups(%u):", (unsigned)Groups.size());
+ LOG(" Groups (%u):", (unsigned)Groups.size());
for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
{
LOG(" '%s'" , itr->c_str());
@@ -76,13 +112,41 @@ public:
// List all the permissions for the player:
AStringVector Permissions = m_Mgr.GetPlayerPermissions(a_PlayerUUID);
- LOG(" Permissions(%u):", (unsigned)Permissions.size());
+ LOG(" Permissions (%u):", (unsigned)Permissions.size());
for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
{
LOG(" '%s'", itr->c_str());
} // for itr - Groups[]
}
+
+ void ReportRankGroups(const AString & a_RankName)
+ {
+ AStringVector Groups = m_Mgr.GetRankGroups(a_RankName);
+ LOG("Groups in rank %s: %u", a_RankName.c_str(), (unsigned)Groups.size());
+ for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
+ {
+ LOG(" '%s'", itr->c_str());
+ }
+ AStringVector Permissions = m_Mgr.GetRankPermissions(a_RankName);
+ LOG("Permissions in rank %s: %u", a_RankName.c_str(), (unsigned)Permissions.size());
+ for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
+ {
+ LOG(" '%s'", itr->c_str());
+ }
+ }
+
+
+ void ReportGroupPermissions(const AString & a_GroupName)
+ {
+ AStringVector Permissions = m_Mgr.GetGroupPermissions(a_GroupName);
+ LOG("Permissions in group %s: %u", a_GroupName.c_str(), (unsigned)Permissions.size());
+ for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
+ {
+ LOG(" '%s'", itr->c_str());
+ }
+ }
+
protected:
cRankManager m_Mgr;
} g_RankMgrTest;
@@ -202,9 +266,25 @@ AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
AStringVector cRankManager::GetRankGroups(const AString & a_RankName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
AStringVector res;
- res.push_back(Printf("%s: DummyGroup", __FUNCTION__));
+ try
+ {
+ SQLite::Statement stmt(m_DB,
+ "SELECT PermGroup.Name FROM PermGroup "
+ "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermGroup.PermGroupID "
+ "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID "
+ "WHERE Rank.Name = ?"
+ );
+ stmt.bind(1, a_RankName);
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get rank groups from DB: %s", __FUNCTION__, ex.what());
+ }
return res;
}
@@ -214,9 +294,24 @@ AStringVector cRankManager::GetRankGroups(const AString & a_RankName)
AStringVector cRankManager::GetGroupPermissions(const AString & a_GroupName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
AStringVector res;
- res.push_back(Printf("%s: DummyPermission", __FUNCTION__));
+ try
+ {
+ SQLite::Statement stmt(m_DB,
+ "SELECT PermissionItem.Permission FROM PermissionItem "
+ "LEFT JOIN PermGroup ON PermGroup.PermGroupID = PermissionItem.PermGroupID "
+ "WHERE PermGroup.Name = ?"
+ );
+ stmt.bind(1, a_GroupName);
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get group permissions from DB: %s", __FUNCTION__, ex.what());
+ }
return res;
}
@@ -226,9 +321,25 @@ AStringVector cRankManager::GetGroupPermissions(const AString & a_GroupName)
AStringVector cRankManager::GetRankPermissions(const AString & a_RankName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
AStringVector res;
- res.push_back(Printf("%s: DummyPermission", __FUNCTION__));
+ try
+ {
+ SQLite::Statement stmt(m_DB,
+ "SELECT PermissionItem.Permission FROM PermissionItem "
+ "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermissionItem.PermGroupID "
+ "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID "
+ "WHERE Rank.Name = ?"
+ );
+ stmt.bind(1, a_RankName);
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get rank permissions from DB: %s", __FUNCTION__, ex.what());
+ }
return res;
}
@@ -238,9 +349,19 @@ AStringVector cRankManager::GetRankPermissions(const AString & a_RankName)
AStringVector cRankManager::GetAllRanks(void)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
AStringVector res;
- res.push_back(Printf("%s: DummyRank", __FUNCTION__));
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT Name FROM Rank");
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
+ }
return res;
}
@@ -250,9 +371,19 @@ AStringVector cRankManager::GetAllRanks(void)
AStringVector cRankManager::GetAllGroups(void)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
AStringVector res;
- res.push_back(Printf("%s: DummyGroup", __FUNCTION__));
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT Name FROM PermGroup");
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get groups from DB: %s", __FUNCTION__, ex.what());
+ }
return res;
}
@@ -262,9 +393,19 @@ AStringVector cRankManager::GetAllGroups(void)
AStringVector cRankManager::GetAllPermissions(void)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
AStringVector res;
- res.push_back(Printf("%s: DummyPermission", __FUNCTION__));
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT Permission FROM PermissionItem");
+ while (stmt.executeStep())
+ {
+ res.push_back(stmt.getColumn(0).getText());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get permissions from DB: %s", __FUNCTION__, ex.what());
+ }
return res;
}
diff --git a/src/RankManager.h b/src/RankManager.h
index 0c35b555f..9a1828275 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -28,13 +28,16 @@ public:
/** Returns the permissions that the specified player has assigned to them. */
AStringVector GetPlayerPermissions(const AString & a_PlayerUUID);
- /** Returns the names of groups that the specified rank has assigned to it. */
+ /** Returns the names of groups that the specified rank has assigned to it.
+ Returns an empty vector if the rank doesn't exist. */
AStringVector GetRankGroups(const AString & a_RankName);
- /** Returns the permissions that the specified group has assigned to it. */
+ /** Returns the permissions that the specified group has assigned to it.
+ Returns an empty vector if the group doesn't exist. */
AStringVector GetGroupPermissions(const AString & a_GroupName);
- /** Returns all permissions that the specified rank has assigned to it, through all its groups. */
+ /** Returns all permissions that the specified rank has assigned to it, through all its groups.
+ Returns an empty vector if the rank doesn't exist. Any non-existent groups are ignored. */
AStringVector GetRankPermissions(const AString & a_RankName);
/** Returns the names of all defined ranks. */
From 3d68466ab03c3f7f2879451a57acba65ed5b197f Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 8 Aug 2014 18:55:05 +0200
Subject: [PATCH 121/751] Send the old slab to the client when the interact
cancelled.
---
src/Blocks/BlockSlab.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h
index 214445eda..28fdbe7af 100644
--- a/src/Blocks/BlockSlab.h
+++ b/src/Blocks/BlockSlab.h
@@ -110,6 +110,17 @@ public:
{
return ((a_BlockType == E_BLOCK_WOODEN_SLAB) || (a_BlockType == E_BLOCK_STONE_SLAB));
}
+
+
+ virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
+ {
+ if ((a_BlockFace == BLOCK_FACE_NONE) || (a_Player->GetEquippedItem().m_ItemType != (short)m_BlockType))
+ {
+ return;
+ }
+
+ a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ }
/// Converts the single-slab blocktype to its equivalent double-slab blocktype
From 89333c5870efb438a38786fd67b82daff0482d9a Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 8 Aug 2014 21:30:47 +0200
Subject: [PATCH 122/751] RankMgr: Finished API implementation.
---
src/RankManager.cpp | 421 ++++++++++++++++++++++++++++++++++++++++----
src/RankManager.h | 18 +-
2 files changed, 401 insertions(+), 38 deletions(-)
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index ec9ac1b1d..8a3b19c15 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -11,7 +11,7 @@
-//*
+/*
// This code is for internal testing while developing the cRankManager class
static class cRankMgrTest
{
@@ -30,30 +30,35 @@ public:
// Add a rank, a few groups and permissions and set the player to use them:
LOG("Adding data...");
- m_Mgr.AddRank("TestRank", "[test]", "[/test]", "7");
+ m_Mgr.AddRank("TestRank1", "[test]", "[/test]", "7");
+ m_Mgr.AddRank("TestRank2", "[t2]", "[/t2]", "8");
m_Mgr.AddGroup("TestGroup1");
m_Mgr.AddGroup("TestGroup2");
- m_Mgr.AddGroupToRank("TestGroup1", "TestRank");
- m_Mgr.AddGroupToRank("TestGroup2", "TestRank");
+ m_Mgr.AddGroupToRank("TestGroup1", "TestRank1");
+ m_Mgr.AddGroupToRank("TestGroup2", "TestRank1");
+ m_Mgr.AddGroupToRank("TestGroup2", "TestRank2");
m_Mgr.AddPermissionToGroup("testpermission1.1", "TestGroup1");
m_Mgr.AddPermissionToGroup("testpermission1.2", "TestGroup1");
+ m_Mgr.AddPermissionToGroup("testpermission1.3", "TestGroup1");
+ m_Mgr.AddPermissionToGroup("common", "TestGroup1");
m_Mgr.AddPermissionToGroup("testpermission2.1", "TestGroup2");
- m_Mgr.SetPlayerRank(UUID, "TestRank");
+ m_Mgr.AddPermissionToGroup("common", "TestGroup2");
+ m_Mgr.SetPlayerRank(UUID, "xoft", "TestRank1");
// Test the added data:
LOG("Testing the added data:");
- LOG("IsGroupInRank(TestGroup1, TestRank) = %s", m_Mgr.IsGroupInRank("TestGroup1", "TestRank") ? "true" : "false");
- LOG("IsGroupInRank(TestGroup3, TestRank) = %s", m_Mgr.IsGroupInRank("TestGroup3", "TestRank") ? "true" : "false");
- LOG("IsPermissionInGroup(testpermission1.2, TestGroup1) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup1") ? "true" : "false");
- LOG("IsPermissionInGroup(testpermission1.2, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup2") ? "true" : "false");
- LOG("IsPermissionInGroup(testpermission1.3, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.3", "TestGroup2") ? "true" : "false");
+ LOG("IsGroupInRank(TestGroup1, TestRank1) = %s", m_Mgr.IsGroupInRank("TestGroup1", "TestRank1") ? "true" : "false");
+ LOG("IsGroupInRank(TestGroup3, TestRank1) = %s", m_Mgr.IsGroupInRank("TestGroup3", "TestRank1") ? "true" : "false");
+ LOG("IsPermissionInGroup(testpermission1.2, TestGroup1) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup1") ? "true" : "false"); // Existing permission, in group
+ LOG("IsPermissionInGroup(testpermission1.2, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup2") ? "true" : "false"); // Existing permission, not in group
+ LOG("IsPermissionInGroup(testpermission1.9, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.9", "TestGroup2") ? "true" : "false"); // Non-existing permission
LOG("IsPlayerRankSet(%s) = %s", UUID.c_str(), m_Mgr.IsPlayerRankSet(UUID) ? "true" : "false");
LOG("IsPlayerRankSet(%s1) = %s", UUID.c_str(), m_Mgr.IsPlayerRankSet(UUID + "1") ? "true" : "false");
LOG("GroupExists(TestGroup1) = %s", m_Mgr.GroupExists("TestGroup1") ? "true" : "false");
LOG("GroupExists(TestGroup3) = %s", m_Mgr.GroupExists("TestGroup3") ? "true" : "false");
- LOG("RankExists(TestRank) = %s", m_Mgr.RankExists("TestRank") ? "true" : "false");
+ LOG("RankExists(TestRank1) = %s", m_Mgr.RankExists("TestRank1") ? "true" : "false");
LOG("RankExists(NonexistentRank) = %s", m_Mgr.RankExists("NonexistentRank") ? "true" : "false");
- ReportRankGroups("TestRank");
+ ReportRankGroups("TestRank1");
ReportRankGroups("NonexistentRank");
ReportGroupPermissions("TestGroup1");
ReportGroupPermissions("NonexistentGroup");
@@ -64,7 +69,65 @@ public:
// Test the assignments above:
LOG("After-assignment test:");
ReportPlayer(UUID);
+
+ // Test removing a permission from a group:
+ LOG("Removing permission testpermission1.3 from group TestGroup1.");
+ m_Mgr.RemovePermissionFromGroup("testpermission1.3", "TestGroup1");
+ ReportGroupPermissions("TestGroup1");
+ LOG("Removing permission common from group TestGroup1.");
+ m_Mgr.RemovePermissionFromGroup("common", "TestGroup1");
+ ReportGroupPermissions("TestGroup1"); // Check that it's not present
+ ReportGroupPermissions("TestGroup2"); // Check that it's still present here
+
+ // Test removing a group from rank:
+ LOG("Removing group TestGroup2 from rank TestRank1.");
+ m_Mgr.RemoveGroupFromRank("TestGroup2", "TestRank1");
+ ReportRankGroups("TestRank1");
+ LOG("Removing group TestGroup3 from rank TestRank1.");
+ m_Mgr.RemoveGroupFromRank("TestGroup3", "TestRank1");
+ ReportRankGroups("TestRank1");
+
+ // Test re-adding the groups:
+ LOG("Re-adding groups to TestRank1.");
+ m_Mgr.AddGroupToRank("TestGroup1", "TestRank1");
+ m_Mgr.AddGroupToRank("TestGroup2", "TestRank1");
+ ReportRankGroups("TestRank1");
+
+ // Test removing a group altogether:
+ LOG("Removing group TestGroup2");
+ m_Mgr.RemoveGroup("TestGroup2");
+ ReportAll();
+
+ // Test removing a rank:
+ LOG("Removing rank TestRank2, replacing with rank TestRank1.");
+ m_Mgr.RemoveRank("TestRank2", "TestRank1");
+ ReportAll();
+ LOG("Removing rank Test altogether.");
+ m_Mgr.RemoveRank("Test", "");
+ ReportAll();
+ // Test renaming a rank:
+ LOG("Renaming rank TestRank1 to Test");
+ m_Mgr.RenameRank("TestRank1", "Test");
+ ReportRankGroups("TestRank1");
+ ReportRankGroups("Test");
+ LOG("Player after renaming:");
+ ReportPlayer(UUID);
+
+ // Test renaming a group:
+ LOG("Renaming group TestGroup1 to Test");
+ m_Mgr.RenameGroup("TestGroup1", "Test");
+ ReportGroupPermissions("TestGroup1");
+ ReportGroupPermissions("Test");
+ LOG("Player after renaming:");
+ ReportPlayer(UUID);
+ m_Mgr.RenameGroup("Test", "TestGroup1");
+
+ // Test removing the rank in favor of another one:
+ m_Mgr.RemoveRank("Test", "TestRank2");
+ LOG("After-removal test:");
+ ReportPlayer(UUID);
+
LOG("Done.");
}
@@ -238,7 +301,7 @@ AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
{
// Prepare the DB statement:
SQLite::Statement stmt(m_DB,
- "SELECT PermissionItem.Permission FROM PermissionItem "
+ "SELECT DISTINCT(PermissionItem.Permission) FROM PermissionItem "
"LEFT JOIN RankPermGroup "
"ON PermissionItem.PermGroupID = RankPermGroup.PermGroupID "
"LEFT JOIN PlayerRank "
@@ -396,7 +459,7 @@ AStringVector cRankManager::GetAllPermissions(void)
AStringVector res;
try
{
- SQLite::Statement stmt(m_DB, "SELECT Permission FROM PermissionItem");
+ SQLite::Statement stmt(m_DB, "SELECT DISTINCT(Permission) FROM PermissionItem");
while (stmt.executeStep())
{
res.push_back(stmt.getColumn(0).getText());
@@ -413,17 +476,43 @@ AStringVector cRankManager::GetAllPermissions(void)
-void cRankManager::GetPlayerMsgVisuals(
+bool cRankManager::GetPlayerMsgVisuals(
const AString & a_PlayerUUID,
AString & a_MsgPrefix,
AString & a_MsgSuffix,
AString & a_MsgNameColorCode
)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
- a_MsgPrefix = Printf("%s: DummyPrefix", __FUNCTION__);
- a_MsgSuffix = Printf("%s: DummySuffix", __FUNCTION__);
- a_MsgNameColorCode = Printf("%s: DummyMsgNameColorCode", __FUNCTION__);
+ AStringVector res;
+ try
+ {
+ SQLite::Statement stmt(m_DB,
+ "SELECT Rank.MsgPrefix, Rank.MsgSuffix, Rank.MsgNameColorCode FROM Rank "
+ "LEFT JOIN PlayerRank ON Rank.RankID = PlayerRank.RankID "
+ "WHERE PlayerRank.PlayerUUID = ?"
+ );
+ stmt.bind(1, a_PlayerUUID);
+ if (!stmt.executeStep())
+ {
+ LOGD("%s: Player UUID %s not found in the DB, returning empty values.", __FUNCTION__, a_PlayerUUID.c_str());
+ a_MsgPrefix.clear();
+ a_MsgSuffix.clear();
+ a_MsgNameColorCode.clear();
+ return false;
+ }
+ a_MsgPrefix = stmt.getColumn(0).getText();
+ a_MsgSuffix = stmt.getColumn(1).getText();
+ a_MsgNameColorCode = stmt.getColumn(2).getText();
+ return true;
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get ranks from DB: %s. Returning empty values.", __FUNCTION__, ex.what());
+ }
+ a_MsgPrefix.clear();
+ a_MsgSuffix.clear();
+ a_MsgNameColorCode.clear();
+ return false;
}
@@ -659,7 +748,73 @@ bool cRankManager::AddPermissionToGroup(const AString & a_Permission, const AStr
void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ AStringVector res;
+ try
+ {
+ // Wrap everything into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Get the RankID for the rank being removed:
+ int RemoveRankID;
+ {
+ SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
+ stmt.bind(1, a_RankName);
+ if (!stmt.executeStep())
+ {
+ LOGINFO("%s: Rank %s was not found. Skipping.", __FUNCTION__, a_RankName.c_str());
+ return;
+ }
+ RemoveRankID = stmt.getColumn(0).getInt();
+ }
+
+ // Get the RankID for the replacement rank:
+ int ReplacementRankID = -1;
+ {
+ SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
+ stmt.bind(1, a_ReplacementRankName);
+ if (stmt.executeStep())
+ {
+ ReplacementRankID = stmt.getColumn(0).getInt();
+ }
+ }
+
+ // Remove the rank's bindings to groups:
+ {
+ SQLite::Statement stmt(m_DB, "DELETE FROM RankPermGroup WHERE RankID = ?");
+ stmt.bind(1, RemoveRankID);
+ stmt.exec();
+ }
+
+ // Adjust players:
+ if (ReplacementRankID == -1)
+ {
+ // No replacement, just delete all the players that have the rank:
+ SQLite::Statement stmt(m_DB, "DELETE FROM PlayerRank WHERE RankID = ?");
+ stmt.bind(1, RemoveRankID);
+ stmt.exec();
+ }
+ else
+ {
+ // Replacement available, change all the player records:
+ SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET RankID = ? WHERE RankID = ?");
+ stmt.bind(1, ReplacementRankID);
+ stmt.bind(2, RemoveRankID);
+ stmt.exec();
+ }
+
+ // Remove the rank from the DB:
+ {
+ SQLite::Statement stmt(m_DB, "DELETE FROM Rank WHERE RankID = ?");
+ stmt.bind(1, RemoveRankID);
+ stmt.exec();
+ }
+
+ trans.commit();
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to remove rank from DB: %s", __FUNCTION__, ex.what());
+ }
}
@@ -668,16 +823,105 @@ void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_Repl
void cRankManager::RemoveGroup(const AString & a_GroupName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ try
+ {
+ // Wrap everything into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Get the ID of the group:
+ int GroupID;
+ {
+ SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, a_GroupName);
+ if (!stmt.executeStep())
+ {
+ LOGINFO("%s: Group %s was not found, skipping.", __FUNCTION__, a_GroupName.c_str());
+ return;
+ }
+ GroupID = stmt.getColumn(0).getInt();
+ }
+
+ // Remove all permissions from the group:
+ {
+ SQLite::Statement stmt(m_DB, "DELETE FROM PermissionItem WHERE PermGroupID = ?");
+ stmt.bind(1, GroupID);
+ stmt.exec();
+ }
+
+ // Remove the group from all ranks that contain it:
+ {
+ SQLite::Statement stmt(m_DB, "DELETE FROM RankPermGroup WHERE PermGroupID = ?");
+ stmt.bind(1, GroupID);
+ stmt.exec();
+ }
+
+ // Remove the group itself:
+ {
+ SQLite::Statement stmt(m_DB, "DELETE FROM PermGroup WHERE PermGroupID = ?");
+ stmt.bind(1, GroupID);
+ stmt.exec();
+ }
+
+ trans.commit();
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to remove group %s from DB: %s", __FUNCTION__, a_GroupName.c_str(), ex.what());
+ }
}
-void cRankManager::RemoveGroupFromRank(const AString & a_RankName, const AString & a_GroupName)
+void cRankManager::RemoveGroupFromRank(const AString & a_GroupName, const AString & a_RankName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ try
+ {
+ // Wrap everything into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Get the IDs of the group and the rank:
+ int GroupID, RankID;
+ {
+ SQLite::Statement stmt(m_DB,
+ "SELECT PermGroup.PermGroupID, Rank.RankID FROM PermGroup "
+ "LEFT JOIN RankPermGroup ON RankPermGroup.PermGroupID = PermGroup.PermGroupID "
+ "LEFT JOIN Rank ON Rank.RankID = RankPermGroup.RankID "
+ "WHERE PermGroup.Name = ? AND Rank.Name = ?"
+ );
+ stmt.bind(1, a_GroupName);
+ stmt.bind(2, a_RankName);
+ if (!stmt.executeStep())
+ {
+ LOGINFO("%s: Group %s was not found in rank %s, skipping.", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str());
+ return;
+ }
+ GroupID = stmt.getColumn(0).getInt();
+ RankID = stmt.getColumn(1).getInt();
+ }
+
+ // Remove the group from all ranks that contain it:
+ {
+ SQLite::Statement stmt(m_DB, "DELETE FROM RankPermGroup WHERE PermGroupID = ?");
+ stmt.bind(1, GroupID);
+ stmt.exec();
+ }
+
+ // Remove the group-to-rank binding:
+ {
+ SQLite::Statement stmt(m_DB, "DELETE FROM RankPermGroup WHERE PermGroupID = ? AND RankID = ?");
+ stmt.bind(1, GroupID);
+ stmt.bind(1, RankID);
+ stmt.exec();
+ }
+
+ trans.commit();
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to remove group %s from rank %s in the DB: %s", __FUNCTION__, a_GroupName.c_str(), a_RankName.c_str(), ex.what());
+ }
}
@@ -686,7 +930,40 @@ void cRankManager::RemoveGroupFromRank(const AString & a_RankName, const AString
void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ try
+ {
+ // Wrap everything into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Get the ID of the group:
+ int GroupID;
+ {
+ SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, a_GroupName);
+ if (!stmt.executeStep())
+ {
+ LOGINFO("%s: Group %s was not found, skipping.", __FUNCTION__, a_GroupName.c_str());
+ return;
+ }
+ GroupID = stmt.getColumn(0).getInt();
+ }
+
+ // Remove the permission from the group:
+ {
+ SQLite::Statement stmt(m_DB, "DELETE FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
+ stmt.bind(1, GroupID);
+ stmt.bind(2, a_Permission);
+ stmt.exec();
+ }
+
+ trans.commit();
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to remove permission %s from group %s in DB: %s",
+ __FUNCTION__, a_Permission.c_str(), a_GroupName.c_str(), ex.what()
+ );
+ }
}
@@ -695,7 +972,39 @@ void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const
bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ try
+ {
+ // Wrap everything into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Check that NewName doesn't exist:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
+ stmt.bind(1, a_NewName);
+ if (stmt.executeStep())
+ {
+ LOGD("%s: Rank %s is already present, cannot rename %s", __FUNCTION__, a_NewName.c_str(), a_OldName.c_str());
+ return false;
+ }
+ }
+
+ // Rename:
+ bool res;
+ {
+ SQLite::Statement stmt(m_DB, "UPDATE Rank SET Name = ? WHERE Name = ?");
+ stmt.bind(1, a_NewName);
+ stmt.bind(2, a_OldName);
+ res = (stmt.exec() > 0);
+ }
+
+ trans.commit();
+ return res;
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to rename rank %s to %s in DB: %s",
+ __FUNCTION__, a_OldName.c_str(), a_NewName.c_str(), ex.what());
+ }
return false;
}
@@ -705,7 +1014,39 @@ bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewNa
bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewName)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ try
+ {
+ // Wrap everything into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Check that NewName doesn't exist:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, a_NewName);
+ if (stmt.executeStep())
+ {
+ LOGD("%s: Group %s is already present, cannot rename %s", __FUNCTION__, a_NewName.c_str(), a_OldName.c_str());
+ return false;
+ }
+ }
+
+ // Rename:
+ bool res;
+ {
+ SQLite::Statement stmt(m_DB, "UPDATE PermGroup SET Name = ? WHERE Name = ?");
+ stmt.bind(1, a_NewName);
+ stmt.bind(2, a_OldName);
+ res = (stmt.exec() > 0);
+ }
+
+ trans.commit();
+ return res;
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to rename group %s to %s in DB: %s",
+ __FUNCTION__, a_OldName.c_str(), a_NewName.c_str(), ex.what());
+ }
return false;
}
@@ -713,7 +1054,7 @@ bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewN
-void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a_RankName)
+void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName)
{
try
{
@@ -735,9 +1076,10 @@ void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a
// Update the player's rank, if already in DB:
{
- SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET RankID = ? WHERE PlayerUUID = ?");
+ SQLite::Statement stmt(m_DB, "UPDATE PlayerRank SET RankID = ?, PlayerName = ? WHERE PlayerUUID = ?");
stmt.bind(1, RankID);
- stmt.bind(2, a_PlayerUUID);
+ stmt.bind(2, a_PlayerName);
+ stmt.bind(3, a_PlayerUUID);
if (stmt.exec() > 0)
{
// Successfully updated the player's rank
@@ -747,9 +1089,10 @@ void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a
}
// The player is not yet in the DB, add them:
- SQLite::Statement stmt(m_DB, "INSERT INTO PlayerRank (RankID, PlayerUUID) VALUES (?, ?)");
+ SQLite::Statement stmt(m_DB, "INSERT INTO PlayerRank (RankID, PlayerUUID, PlayerName) VALUES (?, ?, ?)");
stmt.bind(1, RankID);
stmt.bind(2, a_PlayerUUID);
+ stmt.bind(3, a_PlayerName);
if (stmt.exec() > 0)
{
// Successfully added the player
@@ -780,7 +1123,23 @@ void cRankManager::SetRankVisuals(
const AString & a_MsgNameColorCode
)
{
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
+ AStringVector res;
+ try
+ {
+ SQLite::Statement stmt(m_DB, "UPDATE Rank SET MsgPrefix = ?, MsgSuffix = ?, MsgNameColorCode = ? WHERE Name = ?");
+ stmt.bind(1, a_MsgPrefix);
+ stmt.bind(2, a_MsgSuffix);
+ stmt.bind(1, a_MsgNameColorCode);
+ stmt.bind(2, a_RankName);
+ if (!stmt.executeStep())
+ {
+ LOGINFO("%s: Rank %s not found, visuals not set.", __FUNCTION__, a_RankName.c_str());
+ }
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
+ }
}
diff --git a/src/RankManager.h b/src/RankManager.h
index 9a1828275..e13febdac 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -49,8 +49,9 @@ public:
/** Returns all the distinct permissions that are stored in the DB. */
AStringVector GetAllPermissions(void);
- /** Returns the message visuals (prefix, postfix, color) for the specified player. */
- void GetPlayerMsgVisuals(
+ /** Returns the message visuals (prefix, postfix, color) for the specified player.
+ Returns true if the visuals were read from the DB, false if not (player not found etc). */
+ bool GetPlayerMsgVisuals(
const AString & a_PlayerUUID,
AString & a_MsgPrefix,
AString & a_MsgSuffix,
@@ -79,7 +80,9 @@ public:
bool AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName);
/** Removes the specified rank.
- All players assigned to that rank will be re-assigned to a_ReplacementRankName, unless it is empty. */
+ All players assigned to that rank will be re-assigned to a_ReplacementRankName.
+ If a_ReplacementRankName is empty or not a valid rank, the player will be removed from the DB,
+ which means they will receive the default rank the next time they are queried. */
void RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName);
/** Removes the specified group completely.
@@ -88,7 +91,7 @@ public:
/** Removes the specified group from the specified rank.
The group will stay defined, even if no rank is using it. */
- void RemoveGroupFromRank(const AString & a_RankName, const AString & a_GroupName);
+ void RemoveGroupFromRank(const AString & a_GroupName, const AString & a_RankName);
/** Removes the specified permission from the specified group. */
void RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName);
@@ -104,10 +107,11 @@ public:
bool RenameGroup(const AString & a_OldName, const AString & a_NewName);
/** Sets the specified player's rank.
- If the player already had rank assigned to them, it is overwritten with the new rank.
+ If the player already had rank assigned to them, it is overwritten with the new rank and name.
Note that this doesn't change the cPlayer if the player is already connected, you need to update all the
- cPlayer instances manually. */
- void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_RankName);
+ cPlayer instances manually.
+ The PlayerName is provided for reference, so that GetRankPlayerNames() can work. */
+ void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName);
/** Sets the message visuals of an existing rank. No action if the rank name is not found. */
void SetRankVisuals(
From ebfc0fdc676eb4e0e99fc59ab6da6919fa2ef471 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 8 Aug 2014 22:04:53 +0200
Subject: [PATCH 123/751] Added comment.
---
src/Blocks/BlockSlab.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h
index 28fdbe7af..49f00c88c 100644
--- a/src/Blocks/BlockSlab.h
+++ b/src/Blocks/BlockSlab.h
@@ -119,6 +119,9 @@ public:
return;
}
+ /* Sends the slab back to the client.
+ The normal back sending adds the block face to the locations, but this don't work because the Y-Coordinate with the block face
+ is one higher than the real slab position. */
a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
From 32e1e9a5536f92d074d51cca207f21c372973629 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 8 Aug 2014 18:38:20 +0200
Subject: [PATCH 124/751] Renamed m_DoDaylightCycle to m_CycleDaylight.
---
src/World.cpp | 6 +++---
src/World.h | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/World.cpp b/src/World.cpp
index 7ed8bc1e4..ab46e886c 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -243,7 +243,7 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
#endif
m_Dimension(a_Dimension),
m_IsSpawnExplicitlySet(false),
- m_DoDaylightCycle(true),
+ m_CycleDaylight(true),
m_WorldAgeSecs(0),
m_TimeOfDaySecs(0),
m_WorldAge(0),
@@ -832,7 +832,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
m_WorldAgeSecs += (double)a_Dt / 1000.0;
m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0);
- if (m_DoDaylightCycle)
+ if (m_CycleDaylight)
{
// We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
m_TimeOfDaySecs += (double)a_Dt / 1000.0;
@@ -2249,7 +2249,7 @@ void cWorld::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, cons
void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
{
int TimeOfDay = m_TimeOfDay;
- if (!m_DoDaylightCycle)
+ if (!m_CycleDaylight)
{
TimeOfDay *= -1;
if (TimeOfDay == 0)
diff --git a/src/World.h b/src/World.h
index 8ddc69118..4e85087fc 100644
--- a/src/World.h
+++ b/src/World.h
@@ -147,12 +147,12 @@ public:
int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; }
/** Is the daylight cyclus enabled? */
- virtual bool IsDaylightCycleEnabled(void) const { return m_DoDaylightCycle; }
+ virtual bool IsDaylightCycleEnabled(void) const { return m_CycleDaylight; }
/** Sets the daylight cyclus to true/false. */
- virtual void SetDoDaylightCycle(bool a_DoDaylightCycle)
+ virtual void SetDoDaylightCycle(bool a_CycleDaylight)
{
- m_DoDaylightCycle = a_DoDaylightCycle;
+ m_CycleDaylight = a_CycleDaylight;
BroadcastTimeUpdate();
}
@@ -879,7 +879,7 @@ private:
bool m_BroadcastDeathMessages;
bool m_BroadcastAchievementMessages;
- bool m_DoDaylightCycle; // Is the daylight cyclus enabled?
+ bool m_CycleDaylight; // Is the daylight cyclus enabled?
double m_WorldAgeSecs; // World age, in seconds. Is only incremented, cannot be set by plugins.
double m_TimeOfDaySecs; // Time of day in seconds. Can be adjusted. Is wrapped to zero each day.
Int64 m_WorldAge; // World age in ticks, calculated off of m_WorldAgeSecs
From 3df7d8446c4d5387475a8d6c2f1c3d5ab28b28eb Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 8 Aug 2014 23:11:42 +0200
Subject: [PATCH 125/751] cLuaState: Added GetStackValues() auto-generated
templates.
These will read consecutive values off the stack, each value of a type independent of the other values.
Auto-generated because we don't have variadic templates in C++03.
---
src/Bindings/gen_LuaState_Call.lua | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/Bindings/gen_LuaState_Call.lua b/src/Bindings/gen_LuaState_Call.lua
index 17bae82b3..a5d09d4f1 100644
--- a/src/Bindings/gen_LuaState_Call.lua
+++ b/src/Bindings/gen_LuaState_Call.lua
@@ -182,6 +182,33 @@ for _, combination in ipairs(Combinations) do
WriteOverload(f, combination[1], combination[2])
end
+-- Generate the cLuaState::GetStackValues() multi-param templates:
+for i = 2, 6 do
+ f:write("/** Reads ", i, " consecutive values off the stack */\ntemplate <\n")
+
+ -- Write the template function header:
+ local txt = {}
+ for idx = 1, i do
+ table.insert(txt, "\ttypename ArgT" .. idx)
+ end
+ f:write(table.concat(txt, ",\n"))
+
+ -- Write the argument declarations:
+ txt = {}
+ f:write("\n>\nvoid GetStackValues(\n\tint a_BeginPos,\n")
+ for idx = 1, i do
+ table.insert(txt, "\tArgT" .. idx .. " & Arg" .. idx)
+ end
+ f:write(table.concat(txt, ",\n"))
+
+ -- Write the function body:
+ f:write("\n)\n{\n")
+ for idx = 1, i do
+ f:write("\tGetStackValue(a_BeginPos + ", idx - 1, ", Arg", idx, ");\n")
+ end
+ f:write("}\n\n\n\n\n\n")
+end
+
-- Close the generated file
f:close()
From f1dc299fdb6d2460437608ce79da4db9d0bde7f1 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 8 Aug 2014 23:12:22 +0200
Subject: [PATCH 126/751] Exported cRankManager to LuaAPI.
---
src/Bindings/CMakeLists.txt | 1 +
src/Bindings/ManualBindings.cpp | 2 +
src/Bindings/ManualBindings.h | 19 +-
src/Bindings/ManualBindings_RankManager.cpp | 870 ++++++++++++++++++++
src/Root.h | 3 +
5 files changed, 894 insertions(+), 1 deletion(-)
create mode 100644 src/Bindings/ManualBindings_RankManager.cpp
diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt
index a2b381a26..4b8df52f6 100644
--- a/src/Bindings/CMakeLists.txt
+++ b/src/Bindings/CMakeLists.txt
@@ -11,6 +11,7 @@ SET (SRCS
LuaState.cpp
LuaWindow.cpp
ManualBindings.cpp
+ ManualBindings_RankManager.cpp
Plugin.cpp
PluginLua.cpp
PluginManager.cpp
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 042ffb19e..5563fb14a 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -3262,6 +3262,8 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_endmodule(tolua_S);
tolua_function(tolua_S, "md5", tolua_md5);
+
+ BindRankManager(tolua_S);
tolua_endmodule(tolua_S);
}
diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h
index 36161c6a2..0302b9503 100644
--- a/src/Bindings/ManualBindings.h
+++ b/src/Bindings/ManualBindings.h
@@ -1,8 +1,25 @@
#pragma once
struct lua_State;
+
+
+
+
+
+
+/** Provides namespace for the bindings. */
class ManualBindings
{
public:
- static void Bind( lua_State* tolua_S);
+ /** Binds all the manually implemented functions to tolua_S. */
+ static void Bind(lua_State * tolua_S);
+
+protected:
+ /** Binds the manually implemented cRankManager glue code to tolua_S.
+ Implemented in ManualBindings_RankManager.cpp. */
+ static void BindRankManager(lua_State * tolua_S);
};
+
+
+
+
diff --git a/src/Bindings/ManualBindings_RankManager.cpp b/src/Bindings/ManualBindings_RankManager.cpp
new file mode 100644
index 000000000..daa810cd4
--- /dev/null
+++ b/src/Bindings/ManualBindings_RankManager.cpp
@@ -0,0 +1,870 @@
+
+// ManualBindings_RankManager.cpp
+
+// Implements the cRankManager Lua bindings
+
+#include "Globals.h"
+#include "ManualBindings.h"
+#include "../Root.h"
+#include "tolua++/include/tolua++.h"
+#include "LuaState.h"
+
+
+
+
+
+/** Binds cRankManager::AddGroup */
+static int tolua_cRankManager_AddGroup(lua_State * L)
+{
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Read the params:
+ AString GroupName;
+ S.GetStackValue(2, GroupName);
+
+ // Add the group:
+ cRoot::Get()->GetRankManager().AddGroup(GroupName);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::AddGroup */
+static int tolua_cRankManager_AddGroupToRank(lua_State * L)
+{
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Read the params:
+ AString GroupName, RankName;
+ S.GetStackValues(2, GroupName, RankName);
+
+ // Add the group to the rank:
+ cRoot::Get()->GetRankManager().AddGroupToRank(GroupName, RankName);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::AddPermissionToGroup */
+static int tolua_cRankManager_AddPermissionToGroup(lua_State * L)
+{
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Read the params:
+ AString GroupName, Permission;
+ S.GetStackValues(2, Permission, GroupName);
+
+ // Add the group to the rank:
+ cRoot::Get()->GetRankManager().AddPermissionToGroup(Permission, GroupName);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::AddRank */
+static int tolua_cRankManager_AddRank(lua_State * L)
+{
+ // function signature:
+ // cRankManager:AddRank(RankName)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Read the params:
+ AString RankName, MsgPrefix, MsgSuffix, MsgNameColorCode;
+ S.GetStackValues(2, RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
+
+ // Add the rank:
+ cRoot::Get()->GetRankManager().AddRank(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::GetAllGroups */
+static int tolua_cRankManager_GetAllGroups(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetAllGroups() -> arraytable of GroupNames
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamEnd(2)
+ )
+ {
+ return 0;
+ }
+
+ // Get the groups:
+ AStringVector Groups = cRoot::Get()->GetRankManager().GetAllGroups();
+
+ // Push the results:
+ S.Push(Groups);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetAllPermissions */
+static int tolua_cRankManager_GetAllPermissions(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetAllPermissions() -> arraytable of Permissions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamEnd(2)
+ )
+ {
+ return 0;
+ }
+
+ // Get the permissions:
+ AStringVector Permissions = cRoot::Get()->GetRankManager().GetAllPermissions();
+
+ // Push the results:
+ S.Push(Permissions);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetAllRanks */
+static int tolua_cRankManager_GetAllRanks(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetAllRanks() -> arraytable of RankNames
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamEnd(2)
+ )
+ {
+ return 0;
+ }
+
+ // Get the ranks:
+ AStringVector Ranks = cRoot::Get()->GetRankManager().GetAllRanks();
+
+ // Push the results:
+ S.Push(Ranks);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetGroupPermissions */
+static int tolua_cRankManager_GetGroupPermissions(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetGroupPermissions(GroupName) -> arraytable of permissions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName;
+ S.GetStackValue(2, GroupName);
+
+ // Get the permissions:
+ AStringVector Permissions = cRoot::Get()->GetRankManager().GetGroupPermissions(GroupName);
+
+ // Push the results:
+ S.Push(Permissions);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetPlayerGroups */
+static int tolua_cRankManager_GetPlayerGroups(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetPlayerGroups(PlayerUUID) -> arraytable of GroupNames
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString PlayerUUID;
+ S.GetStackValue(2, PlayerUUID);
+
+ // Get the groups:
+ AStringVector Groups = cRoot::Get()->GetRankManager().GetPlayerGroups(PlayerUUID);
+
+ // Push the results:
+ S.Push(Groups);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetPlayerMsgVisuals */
+static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetPlayerMsgVisuals(PlayerUUID) -> string, string, string
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString PlayerUUID;
+ S.GetStackValue(2, PlayerUUID);
+
+ // Get the permissions:
+ AString MsgPrefix, MsgSuffix, MsgNameColorCode;
+ cRoot::Get()->GetRankManager().GetPlayerMsgVisuals(PlayerUUID, MsgPrefix, MsgSuffix, MsgNameColorCode);
+
+ // Push the results:
+ S.Push(MsgPrefix);
+ S.Push(MsgSuffix);
+ S.Push(MsgNameColorCode);
+ return 3;
+}
+
+
+
+
+
+/** Binds cRankManager::GetPlayerPermissions */
+static int tolua_cRankManager_GetPlayerPermissions(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetPlayerPermissions(PlayerUUID) -> arraytable of permissions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString PlayerUUID;
+ S.GetStackValue(2, PlayerUUID);
+
+ // Get the permissions:
+ AStringVector Permissions = cRoot::Get()->GetRankManager().GetPlayerPermissions(PlayerUUID);
+
+ // Push the results:
+ S.Push(Permissions);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetPlayerRankName */
+static int tolua_cRankManager_GetPlayerRankName(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetPlayerRankName(PlayerUUID) -> string
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString PlayerUUID;
+ S.GetStackValue(2, PlayerUUID);
+
+ // Get the rank name:
+ AString RankName = cRoot::Get()->GetRankManager().GetPlayerRankName(PlayerUUID);
+
+ // Push the result:
+ S.Push(RankName);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetRankGroups */
+static int tolua_cRankManager_GetRankGroups(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetRankGroups(RankName) -> arraytable of groupnames
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString RankName;
+ S.GetStackValue(2, RankName);
+
+ // Get the groups:
+ AStringVector Groups = cRoot::Get()->GetRankManager().GetRankGroups(RankName);
+
+ // Push the results:
+ S.Push(Groups);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetRankPermissions */
+static int tolua_cRankManager_GetRankPermissions(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetRankPermissions(RankName) -> arraytable of permissions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString RankName;
+ S.GetStackValue(2, RankName);
+
+ // Get the permissions:
+ AStringVector Permissions = cRoot::Get()->GetRankManager().GetRankPermissions(RankName);
+
+ // Push the results:
+ S.Push(Permissions);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GroupExists */
+static int tolua_cRankManager_GroupExists(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GroupExists(GroupName) -> bool
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName;
+ S.GetStackValue(2, GroupName);
+
+ // Get the response:
+ bool res = cRoot::Get()->GetRankManager().GroupExists(GroupName);
+
+ // Push the result:
+ S.Push(res);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::IsGroupInRank */
+static int tolua_cRankManager_IsGroupInRank(lua_State * L)
+{
+ // function signature:
+ // cRankManager:IsGroupInRank(GroupName, RankName) -> bool
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName, RankName;
+ S.GetStackValues(2, GroupName, RankName);
+
+ // Get the response:
+ bool res = cRoot::Get()->GetRankManager().IsGroupInRank(GroupName, RankName);
+
+ // Push the result:
+ S.Push(res);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::IsPermissionInGroup */
+static int tolua_cRankManager_IsPermissionInGroup(lua_State * L)
+{
+ // function signature:
+ // cRankManager:IsPermissionInGroup(Permission, GroupName) -> bool
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName, Permission;
+ S.GetStackValues(2, Permission, GroupName);
+
+ // Get the response:
+ bool res = cRoot::Get()->GetRankManager().IsPermissionInGroup(Permission, GroupName);
+
+ // Push the result:
+ S.Push(res);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::IsPlayerRankSet */
+static int tolua_cRankManager_IsPlayerRankSet(lua_State * L)
+{
+ // function signature:
+ // cRankManager:IsPlayerRankSet(PlayerUUID) -> bool
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString PlayerUUID;
+ S.GetStackValue(2, PlayerUUID);
+
+ // Get the response:
+ bool res = cRoot::Get()->GetRankManager().IsPlayerRankSet(PlayerUUID);
+
+ // Push the result:
+ S.Push(res);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::RankExists */
+static int tolua_cRankManager_RankExists(lua_State * L)
+{
+ // function signature:
+ // cRankManager:RankExists(RankName) -> bool
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString RankName;
+ S.GetStackValue(2, RankName);
+
+ // Get the response:
+ bool res = cRoot::Get()->GetRankManager().RankExists(RankName);
+
+ // Push the result:
+ S.Push(res);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::RemoveGroup */
+static int tolua_cRankManager_RemoveGroup(lua_State * L)
+{
+ // function signature:
+ // cRankManager:RemoveGroup(GroupName)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName;
+ S.GetStackValue(2, GroupName);
+
+ // Remove the group:
+ cRoot::Get()->GetRankManager().RemoveGroup(GroupName);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::RemoveGroupFromRank */
+static int tolua_cRankManager_RemoveGroupFromRank(lua_State * L)
+{
+ // function signature:
+ // cRankManager:RemoveGroupFromRank(GroupName, RankName)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName, RankName;
+ S.GetStackValues(2, GroupName, RankName);
+
+ // Remove the group:
+ cRoot::Get()->GetRankManager().RemoveGroupFromRank(GroupName, RankName);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::RemovePermissionFromGroup */
+static int tolua_cRankManager_RemovePermissionFromGroup(lua_State * L)
+{
+ // function signature:
+ // cRankManager:RemovePermissionFromGroup(Permission, GroupName)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName, Permission;
+ S.GetStackValues(2, Permission, GroupName);
+
+ // Remove the group:
+ cRoot::Get()->GetRankManager().RemovePermissionFromGroup(Permission, GroupName);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::RemoveRank */
+static int tolua_cRankManager_RemoveRank(lua_State * L)
+{
+ // function signature:
+ // cRankManager:RemoveRank(RankName, [ReplacementRankName])
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ // Param 3 is otpional, defaults to nil -> empty string
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString RankName, ReplacementRankName;
+ S.GetStackValues(2, RankName, ReplacementRankName);
+
+ // Remove the rank:
+ cRoot::Get()->GetRankManager().RemoveRank(RankName, ReplacementRankName);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::RenameGroup */
+static int tolua_cRankManager_RenameGroup(lua_State * L)
+{
+ // function signature:
+ // cRankManager:RenameGroup(OldName, NewName)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString OldName, NewName;
+ S.GetStackValues(2, OldName, NewName);
+
+ // Remove the group:
+ bool res = cRoot::Get()->GetRankManager().RenameGroup(OldName, NewName);
+
+ // Push the result:
+ S.Push(res);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::RenameRank */
+static int tolua_cRankManager_RenameRank(lua_State * L)
+{
+ // function signature:
+ // cRankManager:RenameRank(OldName, NewName)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString OldName, NewName;
+ S.GetStackValues(2, OldName, NewName);
+
+ // Remove the rank:
+ bool res = cRoot::Get()->GetRankManager().RenameRank(OldName, NewName);
+
+ // Push the result:
+ S.Push(res);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::SetPlayerRank */
+static int tolua_cRankManager_SetPlayerRank(lua_State * L)
+{
+ // function signature:
+ // cRankManager:SetPlayerRank(PlayerUUID, PlayerName, RankName)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 4) ||
+ !S.CheckParamEnd(5)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString PlayerUUID, PlayerName, RankName;
+ S.GetStackValues(2, PlayerUUID, PlayerName, RankName);
+
+ // Set the rank:
+ cRoot::Get()->GetRankManager().SetPlayerRank(PlayerUUID, PlayerName, RankName);
+ return 0;
+}
+
+
+
+
+
+/** Binds cRankManager::SetRankVisuals */
+static int tolua_cRankManager_SetRankVisuals(lua_State * L)
+{
+ // function signature:
+ // cRankManager:SetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 5) ||
+ !S.CheckParamEnd(6)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString RankName, MsgPrefix, MsgSuffix, MsgNameColorCode;
+ S.GetStackValues(2, RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
+
+ // Set the visuals:
+ cRoot::Get()->GetRankManager().SetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
+ return 0;
+}
+
+
+
+
+
+void ManualBindings::BindRankManager(lua_State * tolua_S)
+{
+ // Create the cRankManager class in the API:
+ tolua_usertype(tolua_S, "cRankManager");
+ tolua_cclass(tolua_S, "cRankManager", "cRankManager", "", NULL);
+
+ // Fill in the functions (alpha-sorted):
+ tolua_beginmodule(tolua_S, "cRankManager");
+ tolua_function(tolua_S, "AddGroup", tolua_cRankManager_AddGroup);
+ tolua_function(tolua_S, "AddGroupToRank", tolua_cRankManager_AddGroupToRank);
+ tolua_function(tolua_S, "AddPermissionToGroup", tolua_cRankManager_AddPermissionToGroup);
+ tolua_function(tolua_S, "AddRank", tolua_cRankManager_AddRank);
+ tolua_function(tolua_S, "GetAllGroups", tolua_cRankManager_GetAllGroups);
+ tolua_function(tolua_S, "GetAllPermissions", tolua_cRankManager_GetAllPermissions);
+ tolua_function(tolua_S, "GetAllRanks", tolua_cRankManager_GetAllRanks);
+ tolua_function(tolua_S, "GetGroupPermissions", tolua_cRankManager_GetGroupPermissions);
+ tolua_function(tolua_S, "GetPlayerGroups", tolua_cRankManager_GetPlayerGroups);
+ tolua_function(tolua_S, "GetPlayerMsgVisuals", tolua_cRankManager_GetPlayerMsgVisuals);
+ tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerPermissions);
+ tolua_function(tolua_S, "GetPlayerRankName", tolua_cRankManager_GetPlayerRankName);
+ tolua_function(tolua_S, "GetRankGroups", tolua_cRankManager_GetRankGroups);
+ tolua_function(tolua_S, "GetRankPermissions", tolua_cRankManager_GetRankPermissions);
+ tolua_function(tolua_S, "GroupExists", tolua_cRankManager_GroupExists);
+ tolua_function(tolua_S, "IsGroupInRank", tolua_cRankManager_IsGroupInRank);
+ tolua_function(tolua_S, "IsPermissionInGroup", tolua_cRankManager_IsPermissionInGroup);
+ tolua_function(tolua_S, "IsPlayerRankSet", tolua_cRankManager_IsPlayerRankSet);
+ tolua_function(tolua_S, "RankExists", tolua_cRankManager_RankExists);
+ tolua_function(tolua_S, "RemoveGroup", tolua_cRankManager_RemoveGroup);
+ tolua_function(tolua_S, "RemoveGroupFromRank", tolua_cRankManager_RemoveGroupFromRank);
+ tolua_function(tolua_S, "RemovePermissionFromGroup", tolua_cRankManager_RemovePermissionFromGroup);
+ tolua_function(tolua_S, "RemoveRank", tolua_cRankManager_RemoveRank);
+ tolua_function(tolua_S, "RenameGroup", tolua_cRankManager_RenameGroup);
+ tolua_function(tolua_S, "RenameRank", tolua_cRankManager_RenameRank);
+ tolua_function(tolua_S, "SetPlayerRank", tolua_cRankManager_SetPlayerRank);
+ tolua_function(tolua_S, "SetRankVisuals", tolua_cRankManager_SetRankVisuals);
+ tolua_endmodule(tolua_S);
+}
+
+
+
+
diff --git a/src/Root.h b/src/Root.h
index 1cd175ab4..68469c72f 100644
--- a/src/Root.h
+++ b/src/Root.h
@@ -5,6 +5,7 @@
#include "Protocol/MojangAPI.h"
#include "HTTPServer/HTTPServer.h"
#include "Defines.h"
+#include "RankManager.h"
@@ -89,6 +90,7 @@ public:
cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
cMojangAPI & GetMojangAPI (void) { return m_MojangAPI; }
+ cRankManager & GetRankManager (void) { return m_RankManager; }
/** Queues a console command for execution through the cServer class.
The command will be executed in the tick thread
@@ -194,6 +196,7 @@ private:
cPluginManager * m_PluginManager;
cAuthenticator m_Authenticator;
cMojangAPI m_MojangAPI;
+ cRankManager m_RankManager;
cHTTPServer m_HTTPServer;
cMCLogger * m_Log;
From 251f0d5b97bc36fa3c335bf6a1b03aa22503fa47 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 8 Aug 2014 23:13:43 +0200
Subject: [PATCH 127/751] Debuggers: Simple cRankManager test case.
---
MCServer/Plugins/Debuggers/Debuggers.lua | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 7e220952e..a87511fb9 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -81,6 +81,7 @@ function Initialize(Plugin)
TestBlockAreasString()
TestStringBase64()
TestUUIDFromName()
+ TestRankMgr()
--[[
-- Test cCompositeChat usage in console-logging:
@@ -352,6 +353,18 @@ end
+function TestRankMgr()
+ LOG("Testing the rank manager")
+ cRankManager:AddRank("LuaRank")
+ cRankManager:AddGroup("LuaTestGroup")
+ cRankManager:AddGroupToRank("LuaTestGroup", "LuaRank")
+ cRankManager:AddPermissionToGroup("luaperm", "LuaTestGroup")
+end
+
+
+
+
+
function TestSQLiteBindings()
LOG("Testing SQLite bindings...");
From 0001a7c9fc2359078968565a8ab464509362b776 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 9 Aug 2014 17:36:19 +0200
Subject: [PATCH 128/751] RankMgr: Added GetRankVisuals() function.
---
src/Bindings/ManualBindings_RankManager.cpp | 40 +++++++++++++++++++--
src/RankManager.cpp | 37 +++++++++++++++++--
src/RankManager.h | 9 +++++
3 files changed, 81 insertions(+), 5 deletions(-)
diff --git a/src/Bindings/ManualBindings_RankManager.cpp b/src/Bindings/ManualBindings_RankManager.cpp
index daa810cd4..d17672dcb 100644
--- a/src/Bindings/ManualBindings_RankManager.cpp
+++ b/src/Bindings/ManualBindings_RankManager.cpp
@@ -100,8 +100,8 @@ static int tolua_cRankManager_AddRank(lua_State * L)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
- !S.CheckParamString(2) ||
- !S.CheckParamEnd(3)
+ !S.CheckParamString(2, 5) ||
+ !S.CheckParamEnd(6)
)
{
return 0;
@@ -396,6 +396,41 @@ static int tolua_cRankManager_GetRankGroups(lua_State * L)
+/** Binds cRankManager::GetRankVisuals */
+static int tolua_cRankManager_GetRankVisuals(lua_State * L)
+{
+ // function signature:
+ // cRankManager:GetRankVisuals(RankName) -> MsgPrefix, MsgSuffix, MsgNameColorCode
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString RankName;
+ S.GetStackValue(2, RankName);
+
+ // Get the visuals:
+ AString MsgPrefix, MsgSuffix, MsgNameColorCode;
+ cRoot::Get()->GetRankManager().GetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
+
+ // Push the results:
+ S.Push(MsgPrefix);
+ S.Push(MsgSuffix);
+ S.Push(MsgNameColorCode);
+ return 3;
+}
+
+
+
+
+
/** Binds cRankManager::GetRankPermissions */
static int tolua_cRankManager_GetRankPermissions(lua_State * L)
{
@@ -848,6 +883,7 @@ void ManualBindings::BindRankManager(lua_State * tolua_S)
tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerPermissions);
tolua_function(tolua_S, "GetPlayerRankName", tolua_cRankManager_GetPlayerRankName);
tolua_function(tolua_S, "GetRankGroups", tolua_cRankManager_GetRankGroups);
+ tolua_function(tolua_S, "GetRankVisuals", tolua_cRankManager_GetRankVisuals);
tolua_function(tolua_S, "GetRankPermissions", tolua_cRankManager_GetRankPermissions);
tolua_function(tolua_S, "GroupExists", tolua_cRankManager_GroupExists);
tolua_function(tolua_S, "IsGroupInRank", tolua_cRankManager_IsGroupInRank);
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index 8a3b19c15..3627afadb 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -1123,14 +1123,13 @@ void cRankManager::SetRankVisuals(
const AString & a_MsgNameColorCode
)
{
- AStringVector res;
try
{
SQLite::Statement stmt(m_DB, "UPDATE Rank SET MsgPrefix = ?, MsgSuffix = ?, MsgNameColorCode = ? WHERE Name = ?");
stmt.bind(1, a_MsgPrefix);
stmt.bind(2, a_MsgSuffix);
- stmt.bind(1, a_MsgNameColorCode);
- stmt.bind(2, a_RankName);
+ stmt.bind(3, a_MsgNameColorCode);
+ stmt.bind(4, a_RankName);
if (!stmt.executeStep())
{
LOGINFO("%s: Rank %s not found, visuals not set.", __FUNCTION__, a_RankName.c_str());
@@ -1146,6 +1145,38 @@ void cRankManager::SetRankVisuals(
+bool cRankManager::GetRankVisuals(
+ const AString & a_RankName,
+ AString & a_MsgPrefix,
+ AString & a_MsgSuffix,
+ AString & a_MsgNameColorCode
+)
+{
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT MsgPrefix, MsgSuffix, MsgNameColorCode FROM Rank WHERE Name = ?");
+ stmt.bind(1, a_RankName);
+ if (!stmt.executeStep())
+ {
+ // Rank not found
+ return false;
+ }
+ a_MsgPrefix = stmt.getColumn(0).getText();
+ a_MsgSuffix = stmt.getColumn(1).getText();
+ a_MsgNameColorCode = stmt.getColumn(2).getText();
+ return true;
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to get ranks from DB: %s", __FUNCTION__, ex.what());
+ }
+ return false;
+}
+
+
+
+
+
bool cRankManager::RankExists(const AString & a_RankName)
{
try
diff --git a/src/RankManager.h b/src/RankManager.h
index e13febdac..0a43bfe5d 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -121,6 +121,15 @@ public:
const AString & a_MsgNameColorCode
);
+ /** Returns the message visuals of an existing rank.
+ Returns true if successful, false on error (rank doesn't exist). */
+ bool GetRankVisuals(
+ const AString & a_RankName,
+ AString & a_MsgPrefix,
+ AString & a_MsgSuffix,
+ AString & a_MsgNameColorCode
+ );
+
/** Returns true iff the specified rank exists in the DB. */
bool RankExists(const AString & a_RankName);
From 2ab8e763927070eef76963d42933a0d9b87191c2 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 9 Aug 2014 22:34:59 +0200
Subject: [PATCH 129/751] WebAdmin: Added GetURLEncodedString().
---
src/WebAdmin.cpp | 32 ++++++++++++++++++++++++++++++++
src/WebAdmin.h | 5 ++++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp
index f5dc6fde7..ab6925e55 100644
--- a/src/WebAdmin.cpp
+++ b/src/WebAdmin.cpp
@@ -444,6 +444,38 @@ AString cWebAdmin::GetHTMLEscapedString(const AString & a_Input)
+AString cWebAdmin::GetURLEncodedString(const AString & a_Input)
+{
+ // Translation table from nibble to hex:
+ static const char Hex[] = "0123456789abcdef";
+
+ // Preallocate the output to match input:
+ AString dst;
+ size_t len = a_Input.length();
+ dst.reserve(len);
+
+ // Loop over input and substitute whatever is needed:
+ for (size_t i = 0; i < len; i++)
+ {
+ char ch = a_Input[i];
+ if (isalnum(ch) || (ch == '-') || (ch == '_') || (ch == '.') || (ch == '~'))
+ {
+ dst.push_back(ch);
+ }
+ else
+ {
+ dst.push_back('%');
+ dst.push_back(Hex[(ch >> 4) & 0x0f]);
+ dst.push_back(Hex[ch & 0x0f]);
+ }
+ } // for i - a_Input[]
+ return dst;
+}
+
+
+
+
+
AString cWebAdmin::GetBaseURL(const AStringVector & a_URLSplit)
{
AString BaseURL = "./";
diff --git a/src/WebAdmin.h b/src/WebAdmin.h
index d679a097c..018a27b69 100644
--- a/src/WebAdmin.h
+++ b/src/WebAdmin.h
@@ -134,6 +134,9 @@ public:
/** Escapes text passed into it, so it can be embedded into html. */
static AString GetHTMLEscapedString(const AString & a_Input);
+
+ /** Escapes the string for use in an URL */
+ static AString GetURLEncodedString(const AString & a_Input);
AString GetIPv4Ports(void) const { return m_PortsIPv4; }
AString GetIPv6Ports(void) const { return m_PortsIPv6; }
@@ -141,7 +144,7 @@ public:
// tolua_end
/** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */
- AString GetBaseURL(const AStringVector& a_URLSplit);
+ static AString GetBaseURL(const AStringVector & a_URLSplit);
protected:
/** Common base class for request body data handlers */
From 50359ce65670badb72879f09fc9b2f77b2cbeae6 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 9 Aug 2014 22:54:43 +0200
Subject: [PATCH 130/751] WebAdmin: Manually exported string conversion
functions.
ToLua generated an extra return value for GetHTMLEscapedString() and GetURLEncodedString(), making them difficult to use.
---
src/Bindings/ManualBindings.cpp | 60 ++++++++++++++++++++++++++++++++-
src/WebAdmin.h | 10 +++---
2 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index f50bdd7de..c8eb5d138 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2128,6 +2128,62 @@ static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S)
+/** Binding for cWebAdmin::GetHTMLEscapedString.
+Manual code required because ToLua generates an extra return value */
+static int tolua_AllToLua_cWebAdmin_GetHTMLEscapedString(lua_State * tolua_S)
+{
+ // Check the param types:
+ cLuaState S(tolua_S);
+ if (
+ !S.CheckParamUserTable(1, "cWebAdmin") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the parameters:
+ AString Input;
+ S.GetStackValue(2, Input);
+
+ // Convert and return:
+ S.Push(cWebAdmin::GetHTMLEscapedString(Input));
+ return 1;
+}
+
+
+
+
+
+/** Binding for cWebAdmin::GetURLEncodedString.
+Manual code required because ToLua generates an extra return value */
+static int tolua_AllToLua_cWebAdmin_GetURLEncodedString(lua_State * tolua_S)
+{
+ // Check the param types:
+ cLuaState S(tolua_S);
+ if (
+ !S.CheckParamUserTable(1, "cWebAdmin") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the parameters:
+ AString Input;
+ S.GetStackValue(2, Input);
+
+ // Convert and return:
+ S.Push(cWebAdmin::GetURLEncodedString(Input));
+ return 1;
+}
+
+
+
+
+
static int tolua_cWebPlugin_GetTabNames(lua_State * tolua_S)
{
cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S, 1, NULL);
@@ -3264,7 +3320,9 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cWebAdmin");
- tolua_function(tolua_S, "GetPlugins", tolua_cWebAdmin_GetPlugins);
+ tolua_function(tolua_S, "GetHTMLEscapedString", tolua_AllToLua_cWebAdmin_GetHTMLEscapedString);
+ tolua_function(tolua_S, "GetPlugins", tolua_cWebAdmin_GetPlugins);
+ tolua_function(tolua_S, "GetURLEncodedString", tolua_AllToLua_cWebAdmin_GetURLEncodedString);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cWebPlugin");
diff --git a/src/WebAdmin.h b/src/WebAdmin.h
index 018a27b69..f48e8ce9e 100644
--- a/src/WebAdmin.h
+++ b/src/WebAdmin.h
@@ -132,17 +132,17 @@ public:
/** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */
AString GetBaseURL(const AString & a_URL);
+ AString GetIPv4Ports(void) const { return m_PortsIPv4; }
+ AString GetIPv6Ports(void) const { return m_PortsIPv6; }
+
+ // tolua_end
+
/** Escapes text passed into it, so it can be embedded into html. */
static AString GetHTMLEscapedString(const AString & a_Input);
/** Escapes the string for use in an URL */
static AString GetURLEncodedString(const AString & a_Input);
- AString GetIPv4Ports(void) const { return m_PortsIPv4; }
- AString GetIPv6Ports(void) const { return m_PortsIPv6; }
-
- // tolua_end
-
/** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */
static AString GetBaseURL(const AStringVector & a_URLSplit);
From af202c2363131d343d38a1f04850cfd711aef61e Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 9 Aug 2014 22:55:38 +0200
Subject: [PATCH 131/751] Debuggers: Disabled UUID and RankMgr tests.
---
MCServer/Plugins/Debuggers/Debuggers.lua | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index a87511fb9..81cf02f3c 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -80,8 +80,8 @@ function Initialize(Plugin)
TestBlockAreasString()
TestStringBase64()
- TestUUIDFromName()
- TestRankMgr()
+ -- TestUUIDFromName()
+ -- TestRankMgr()
--[[
-- Test cCompositeChat usage in console-logging:
From dcef688ccc0ae60b001ce40fd591a2dfafbac294 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 9 Aug 2014 22:34:59 +0200
Subject: [PATCH 132/751] WebAdmin: Added GetURLEncodedString().
---
src/WebAdmin.cpp | 32 ++++++++++++++++++++++++++++++++
src/WebAdmin.h | 5 ++++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp
index f5dc6fde7..ab6925e55 100644
--- a/src/WebAdmin.cpp
+++ b/src/WebAdmin.cpp
@@ -444,6 +444,38 @@ AString cWebAdmin::GetHTMLEscapedString(const AString & a_Input)
+AString cWebAdmin::GetURLEncodedString(const AString & a_Input)
+{
+ // Translation table from nibble to hex:
+ static const char Hex[] = "0123456789abcdef";
+
+ // Preallocate the output to match input:
+ AString dst;
+ size_t len = a_Input.length();
+ dst.reserve(len);
+
+ // Loop over input and substitute whatever is needed:
+ for (size_t i = 0; i < len; i++)
+ {
+ char ch = a_Input[i];
+ if (isalnum(ch) || (ch == '-') || (ch == '_') || (ch == '.') || (ch == '~'))
+ {
+ dst.push_back(ch);
+ }
+ else
+ {
+ dst.push_back('%');
+ dst.push_back(Hex[(ch >> 4) & 0x0f]);
+ dst.push_back(Hex[ch & 0x0f]);
+ }
+ } // for i - a_Input[]
+ return dst;
+}
+
+
+
+
+
AString cWebAdmin::GetBaseURL(const AStringVector & a_URLSplit)
{
AString BaseURL = "./";
diff --git a/src/WebAdmin.h b/src/WebAdmin.h
index d679a097c..018a27b69 100644
--- a/src/WebAdmin.h
+++ b/src/WebAdmin.h
@@ -134,6 +134,9 @@ public:
/** Escapes text passed into it, so it can be embedded into html. */
static AString GetHTMLEscapedString(const AString & a_Input);
+
+ /** Escapes the string for use in an URL */
+ static AString GetURLEncodedString(const AString & a_Input);
AString GetIPv4Ports(void) const { return m_PortsIPv4; }
AString GetIPv6Ports(void) const { return m_PortsIPv6; }
@@ -141,7 +144,7 @@ public:
// tolua_end
/** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */
- AString GetBaseURL(const AStringVector& a_URLSplit);
+ static AString GetBaseURL(const AStringVector & a_URLSplit);
protected:
/** Common base class for request body data handlers */
From b0dedb01977fe4cd7ebd51db5784d8ca415f1567 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 9 Aug 2014 22:54:43 +0200
Subject: [PATCH 133/751] WebAdmin: Manually exported string conversion
functions.
ToLua generated an extra return value for GetHTMLEscapedString() and GetURLEncodedString(), making them difficult to use.
---
src/Bindings/ManualBindings.cpp | 60 ++++++++++++++++++++++++++++++++-
src/WebAdmin.h | 10 +++---
2 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 8e6156d97..6b40cece8 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2128,6 +2128,62 @@ static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S)
+/** Binding for cWebAdmin::GetHTMLEscapedString.
+Manual code required because ToLua generates an extra return value */
+static int tolua_AllToLua_cWebAdmin_GetHTMLEscapedString(lua_State * tolua_S)
+{
+ // Check the param types:
+ cLuaState S(tolua_S);
+ if (
+ !S.CheckParamUserTable(1, "cWebAdmin") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the parameters:
+ AString Input;
+ S.GetStackValue(2, Input);
+
+ // Convert and return:
+ S.Push(cWebAdmin::GetHTMLEscapedString(Input));
+ return 1;
+}
+
+
+
+
+
+/** Binding for cWebAdmin::GetURLEncodedString.
+Manual code required because ToLua generates an extra return value */
+static int tolua_AllToLua_cWebAdmin_GetURLEncodedString(lua_State * tolua_S)
+{
+ // Check the param types:
+ cLuaState S(tolua_S);
+ if (
+ !S.CheckParamUserTable(1, "cWebAdmin") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the parameters:
+ AString Input;
+ S.GetStackValue(2, Input);
+
+ // Convert and return:
+ S.Push(cWebAdmin::GetURLEncodedString(Input));
+ return 1;
+}
+
+
+
+
+
static int tolua_cWebPlugin_GetTabNames(lua_State * tolua_S)
{
cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S, 1, NULL);
@@ -3264,7 +3320,9 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cWebAdmin");
- tolua_function(tolua_S, "GetPlugins", tolua_cWebAdmin_GetPlugins);
+ tolua_function(tolua_S, "GetHTMLEscapedString", tolua_AllToLua_cWebAdmin_GetHTMLEscapedString);
+ tolua_function(tolua_S, "GetPlugins", tolua_cWebAdmin_GetPlugins);
+ tolua_function(tolua_S, "GetURLEncodedString", tolua_AllToLua_cWebAdmin_GetURLEncodedString);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cWebPlugin");
diff --git a/src/WebAdmin.h b/src/WebAdmin.h
index 018a27b69..f48e8ce9e 100644
--- a/src/WebAdmin.h
+++ b/src/WebAdmin.h
@@ -132,17 +132,17 @@ public:
/** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */
AString GetBaseURL(const AString & a_URL);
+ AString GetIPv4Ports(void) const { return m_PortsIPv4; }
+ AString GetIPv6Ports(void) const { return m_PortsIPv6; }
+
+ // tolua_end
+
/** Escapes text passed into it, so it can be embedded into html. */
static AString GetHTMLEscapedString(const AString & a_Input);
/** Escapes the string for use in an URL */
static AString GetURLEncodedString(const AString & a_Input);
- AString GetIPv4Ports(void) const { return m_PortsIPv4; }
- AString GetIPv6Ports(void) const { return m_PortsIPv6; }
-
- // tolua_end
-
/** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */
static AString GetBaseURL(const AStringVector & a_URLSplit);
From 5eb5411f1e9f3683e8ecb6448877ba6cf34b2dbf Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sun, 10 Aug 2014 11:06:04 +0200
Subject: [PATCH 134/751] Removed an old and outdated comment.
---
src/Generating/FinishGen.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
index e8324095e..eb57a5faa 100644
--- a/src/Generating/FinishGen.cpp
+++ b/src/Generating/FinishGen.cpp
@@ -484,8 +484,6 @@ int cFinishGenSingleTopBlock::GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap
void cFinishGenSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
{
- // Add Lilypads on top of water surface in Swampland
-
int NumToGen = GetNumToGen(a_ChunkDesc.GetBiomeMap());
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
From ecfae286064b4a8fcf6e4df38c09e8055e83de33 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sun, 10 Aug 2014 11:40:33 +0200
Subject: [PATCH 135/751] Changed cStructGenOreNests to take a list of ores +
the block to replace.
---
src/Generating/ComposableGenerator.cpp | 52 ++++++++++++++++++++++-
src/Generating/StructGen.cpp | 58 +++++---------------------
src/Generating/StructGen.h | 26 ++++++++++--
3 files changed, 83 insertions(+), 53 deletions(-)
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index cedb9aeb7..79a92171f 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -400,7 +400,57 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
}
else if (NoCaseCompare(*itr, "OreNests") == 0)
{
- m_FinishGens.push_back(new cStructGenOreNests(Seed));
+ cStructGenOreNests::OreList Ores;
+
+ // Coal vein
+ cStructGenOreNests::OreInfo CoalVein;
+ CoalVein.BlockType = E_BLOCK_COAL_ORE;
+ CoalVein.MaxHeight = 127;
+ CoalVein.NumNests = 50;
+ CoalVein.NestSize = 10;
+ Ores.push_back(CoalVein);
+
+ // Iron vein
+ cStructGenOreNests::OreInfo IronVein;
+ IronVein.BlockType = E_BLOCK_IRON_ORE;
+ IronVein.MaxHeight = 64;
+ IronVein.NumNests = 14;
+ IronVein.NestSize = 6;
+ Ores.push_back(IronVein);
+
+ // Gold vein
+ cStructGenOreNests::OreInfo GoldVein;
+ GoldVein.BlockType = E_BLOCK_GOLD_ORE;
+ GoldVein.MaxHeight = 32;
+ GoldVein.NumNests = 2;
+ GoldVein.NestSize = 6;
+ Ores.push_back(GoldVein);
+
+ // Redstone vein
+ cStructGenOreNests::OreInfo RedstoneVein;
+ RedstoneVein.BlockType = E_BLOCK_REDSTONE_ORE;
+ RedstoneVein.MaxHeight = 16;
+ RedstoneVein.NumNests = 4;
+ RedstoneVein.NestSize = 6;
+ Ores.push_back(RedstoneVein);
+
+ // Lapis vein
+ cStructGenOreNests::OreInfo LapisVein;
+ LapisVein.BlockType = E_BLOCK_LAPIS_ORE;
+ LapisVein.MaxHeight = 30;
+ LapisVein.NumNests = 2;
+ LapisVein.NestSize = 5;
+ Ores.push_back(LapisVein);
+
+ // Diamond vein
+ cStructGenOreNests::OreInfo DiamondVein;
+ DiamondVein.BlockType = E_BLOCK_DIAMOND_ORE;
+ DiamondVein.MaxHeight = 15;
+ DiamondVein.NumNests = 1;
+ DiamondVein.NestSize = 4;
+ Ores.push_back(DiamondVein);
+
+ m_FinishGens.push_back(new cStructGenOreNests(Seed, Ores, E_BLOCK_STONE));
}
else if (NoCaseCompare(*itr, "POCPieces") == 0)
{
diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp
index f7e609353..1a43f2b2e 100644
--- a/src/Generating/StructGen.cpp
+++ b/src/Generating/StructGen.cpp
@@ -12,45 +12,6 @@
-////////////////////////////////////////////////////////////////////////////////
-// cStructGenOreNests configuration:
-
-const int MAX_HEIGHT_COAL = 127;
-const int NUM_NESTS_COAL = 50;
-const int NEST_SIZE_COAL = 10;
-
-const int MAX_HEIGHT_IRON = 64;
-const int NUM_NESTS_IRON = 14;
-const int NEST_SIZE_IRON = 6;
-
-const int MAX_HEIGHT_REDSTONE = 16;
-const int NUM_NESTS_REDSTONE = 4;
-const int NEST_SIZE_REDSTONE = 6;
-
-const int MAX_HEIGHT_GOLD = 32;
-const int NUM_NESTS_GOLD = 2;
-const int NEST_SIZE_GOLD = 6;
-
-const int MAX_HEIGHT_DIAMOND = 15;
-const int NUM_NESTS_DIAMOND = 1;
-const int NEST_SIZE_DIAMOND = 4;
-
-const int MAX_HEIGHT_LAPIS = 30;
-const int NUM_NESTS_LAPIS = 2;
-const int NEST_SIZE_LAPIS = 5;
-
-const int MAX_HEIGHT_DIRT = 127;
-const int NUM_NESTS_DIRT = 20;
-const int NEST_SIZE_DIRT = 32;
-
-const int MAX_HEIGHT_GRAVEL = 70;
-const int NUM_NESTS_GRAVEL = 15;
-const int NEST_SIZE_GRAVEL = 32;
-
-
-
-
-
////////////////////////////////////////////////////////////////////////////////
// cStructGenTrees:
@@ -311,14 +272,15 @@ void cStructGenOreNests::GenFinish(cChunkDesc & a_ChunkDesc)
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
cChunkDef::BlockTypes & BlockTypes = a_ChunkDesc.GetBlockTypes();
- GenerateOre(ChunkX, ChunkZ, E_BLOCK_COAL_ORE, MAX_HEIGHT_COAL, NUM_NESTS_COAL, NEST_SIZE_COAL, BlockTypes, 1);
- GenerateOre(ChunkX, ChunkZ, E_BLOCK_IRON_ORE, MAX_HEIGHT_IRON, NUM_NESTS_IRON, NEST_SIZE_IRON, BlockTypes, 2);
- GenerateOre(ChunkX, ChunkZ, E_BLOCK_REDSTONE_ORE, MAX_HEIGHT_REDSTONE, NUM_NESTS_REDSTONE, NEST_SIZE_REDSTONE, BlockTypes, 3);
- GenerateOre(ChunkX, ChunkZ, E_BLOCK_GOLD_ORE, MAX_HEIGHT_GOLD, NUM_NESTS_GOLD, NEST_SIZE_GOLD, BlockTypes, 4);
- GenerateOre(ChunkX, ChunkZ, E_BLOCK_DIAMOND_ORE, MAX_HEIGHT_DIAMOND, NUM_NESTS_DIAMOND, NEST_SIZE_DIAMOND, BlockTypes, 5);
- GenerateOre(ChunkX, ChunkZ, E_BLOCK_LAPIS_ORE, MAX_HEIGHT_LAPIS, NUM_NESTS_LAPIS, NEST_SIZE_LAPIS, BlockTypes, 6);
- GenerateOre(ChunkX, ChunkZ, E_BLOCK_DIRT, MAX_HEIGHT_DIRT, NUM_NESTS_DIRT, NEST_SIZE_DIRT, BlockTypes, 10);
- GenerateOre(ChunkX, ChunkZ, E_BLOCK_GRAVEL, MAX_HEIGHT_GRAVEL, NUM_NESTS_GRAVEL, NEST_SIZE_GRAVEL, BlockTypes, 11);
+
+ int seq = 1;
+
+ // Generate the ores from the ore list.
+ for (OreList::iterator itr = m_OreList.begin(); itr != m_OreList.end(); ++itr)
+ {
+ GenerateOre(ChunkX, ChunkZ, itr->BlockType, itr->MaxHeight, itr->NumNests, itr->NestSize, BlockTypes, seq);
+ seq++;
+ }
}
@@ -376,7 +338,7 @@ void cStructGenOreNests::GenerateOre(int a_ChunkX, int a_ChunkZ, BLOCKTYPE a_Ore
}
int Index = cChunkDef::MakeIndexNoCheck(BlockX, BlockY, BlockZ);
- if (a_BlockTypes[Index] == E_BLOCK_STONE)
+ if (a_BlockTypes[Index] == m_ToReplace)
{
a_BlockTypes[Index] = a_OreType;
}
diff --git a/src/Generating/StructGen.h b/src/Generating/StructGen.h
index 9176bc192..e2fe8bc1a 100644
--- a/src/Generating/StructGen.h
+++ b/src/Generating/StructGen.h
@@ -76,11 +76,29 @@ class cStructGenOreNests :
public cFinishGen
{
public:
- cStructGenOreNests(int a_Seed) : m_Noise(a_Seed), m_Seed(a_Seed) {}
-
+ struct OreInfo
+ {
+ BLOCKTYPE BlockType; // The type of the nest.
+ int MaxHeight; // The highest possible a nest can occur
+ int NumNests; // How many nests per chunk
+ int NestSize; // The amount of blocks a nest can have.
+ };
+
+ typedef std::vector OreList;
+
+ cStructGenOreNests(int a_Seed, OreList a_OreList, BLOCKTYPE a_ToReplace) :
+ m_Noise(a_Seed),
+ m_Seed(a_Seed),
+ m_OreList(a_OreList),
+ m_ToReplace(a_ToReplace)
+ {}
+
protected:
- cNoise m_Noise;
- int m_Seed;
+ cNoise m_Noise;
+ int m_Seed;
+
+ OreList m_OreList; // A list of possible ores.
+ BLOCKTYPE m_ToReplace;
// cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
From 0ac3c67a21ae6fbd060322d65fcdad4f98148567 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sun, 10 Aug 2014 11:48:05 +0200
Subject: [PATCH 136/751] Added NetherOreNests. It generates Nether Quarts.
---
src/Generating/ComposableGenerator.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index 79a92171f..1ae86a29f 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -398,6 +398,21 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 12);
m_FinishGens.push_back(new cNetherFortGen(Seed, GridSize, MaxOffset, MaxDepth));
}
+ else if (NoCaseCompare(*itr, "NetherOreNests") == 0)
+ {
+ cStructGenOreNests::OreList Ores;
+
+ // Quarts vein
+ cStructGenOreNests::OreInfo QuartsVein;
+ QuartsVein.BlockType = E_BLOCK_NETHER_QUARTZ_ORE;
+ QuartsVein.MaxHeight = 255;
+ QuartsVein.NumNests = 80;
+ QuartsVein.NestSize = 8;
+ Ores.push_back(QuartsVein);
+
+ m_FinishGens.push_back(new cStructGenOreNests(Seed, Ores, E_BLOCK_NETHERRACK));
+
+ }
else if (NoCaseCompare(*itr, "OreNests") == 0)
{
cStructGenOreNests::OreList Ores;
From e529401dbb6d9c6de3b5e81b3308a478fe1a36db Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sun, 10 Aug 2014 11:57:05 +0200
Subject: [PATCH 137/751] Added NaturalPatches generator It generates gravel
and dirt.
---
src/Generating/ComposableGenerator.cpp | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index 1ae86a29f..58ad8fc2e 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -387,6 +387,28 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
m_FinishGens.push_back(new cFinishGenSingleTopBlock(Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks));
}
+ else if (NoCaseCompare(*itr, "NaturalPatches") == 0)
+ {
+ cStructGenOreNests::OreList Ores;
+
+ // Dirt vein
+ cStructGenOreNests::OreInfo DirtVein;
+ DirtVein.BlockType = E_BLOCK_DIRT;
+ DirtVein.MaxHeight = 127;
+ DirtVein.NumNests = 20;
+ DirtVein.NestSize = 32;
+ Ores.push_back(DirtVein);
+
+ // Gravel vein
+ cStructGenOreNests::OreInfo GravelVein;
+ GravelVein.BlockType = E_BLOCK_DIRT;
+ GravelVein.MaxHeight = 127;
+ GravelVein.NumNests = 20;
+ GravelVein.NestSize = 32;
+ Ores.push_back(GravelVein);
+
+ m_FinishGens.push_back(new cStructGenOreNests(Seed, Ores, E_BLOCK_STONE));
+ }
else if (NoCaseCompare(*itr, "NetherClumpFoliage") == 0)
{
m_FinishGens.push_back(new cFinishGenNetherClumpFoliage(Seed));
From cccc321384be18d4ac75e83abf3ce4d19a2a3d56 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 10 Aug 2014 16:46:03 +0200
Subject: [PATCH 138/751] Renamed functions.
---
src/World.cpp | 6 +++---
src/World.h | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/World.cpp b/src/World.cpp
index ab46e886c..dc1d9fedf 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -243,7 +243,7 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
#endif
m_Dimension(a_Dimension),
m_IsSpawnExplicitlySet(false),
- m_CycleDaylight(true),
+ m_IsDaylightCycleEnabled(true),
m_WorldAgeSecs(0),
m_TimeOfDaySecs(0),
m_WorldAge(0),
@@ -832,7 +832,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
m_WorldAgeSecs += (double)a_Dt / 1000.0;
m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0);
- if (m_CycleDaylight)
+ if (m_IsDaylightCycleEnabled)
{
// We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
m_TimeOfDaySecs += (double)a_Dt / 1000.0;
@@ -2249,7 +2249,7 @@ void cWorld::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, cons
void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
{
int TimeOfDay = m_TimeOfDay;
- if (!m_CycleDaylight)
+ if (!m_IsDaylightCycleEnabled)
{
TimeOfDay *= -1;
if (TimeOfDay == 0)
diff --git a/src/World.h b/src/World.h
index 4e85087fc..6df1758e9 100644
--- a/src/World.h
+++ b/src/World.h
@@ -147,12 +147,12 @@ public:
int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; }
/** Is the daylight cyclus enabled? */
- virtual bool IsDaylightCycleEnabled(void) const { return m_CycleDaylight; }
+ virtual bool IsDaylightCycleEnabled(void) const { return m_IsDaylightCycleEnabled; }
/** Sets the daylight cyclus to true/false. */
- virtual void SetDoDaylightCycle(bool a_CycleDaylight)
+ virtual void SetDaylightCycleEnabled(bool a_IsDaylightCycleEnabled)
{
- m_CycleDaylight = a_CycleDaylight;
+ m_IsDaylightCycleEnabled = a_IsDaylightCycleEnabled;
BroadcastTimeUpdate();
}
@@ -879,7 +879,7 @@ private:
bool m_BroadcastDeathMessages;
bool m_BroadcastAchievementMessages;
- bool m_CycleDaylight; // Is the daylight cyclus enabled?
+ bool m_IsDaylightCycleEnabled;
double m_WorldAgeSecs; // World age, in seconds. Is only incremented, cannot be set by plugins.
double m_TimeOfDaySecs; // Time of day in seconds. Can be adjusted. Is wrapped to zero each day.
Int64 m_WorldAge; // World age in ticks, calculated off of m_WorldAgeSecs
From f90078c09ff576d3f8af1554872c53afbdcd6fe0 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 10 Aug 2014 16:48:20 +0200
Subject: [PATCH 139/751] Added IsDaylightCycleEnabled saving.
---
src/World.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/World.cpp b/src/World.cpp
index dc1d9fedf..0ae7f80a6 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -577,6 +577,7 @@ void cWorld::Start(void)
m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true);
m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true);
m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true);
+ m_IsDaylightCycleEnabled = IniFile.GetValueSetB("General", "IsDaylightCycleEnabled", true);
int GameMode = IniFile.GetValueSetI("General", "Gamemode", (int)m_GameMode);
int Weather = IniFile.GetValueSetI("General", "Weather", (int)m_Weather);
@@ -798,6 +799,7 @@ void cWorld::Stop(void)
IniFile.SetValueI("Physics", "TNTShrapnelLevel", (int)m_TNTShrapnelLevel);
IniFile.SetValueB("Mechanics", "CommandBlocksEnabled", m_bCommandBlocksEnabled);
IniFile.SetValueB("Mechanics", "UseChatPrefixes", m_bUseChatPrefixes);
+ IniFile.SetValueB("General", "IsDaylightCycleEnabled", m_IsDaylightCycleEnabled);
IniFile.SetValueI("General", "Weather", (int)m_Weather);
IniFile.SetValueI("General", "TimeInTicks", m_TimeOfDay);
IniFile.WriteFile(m_IniFileName);
From ae611563919d123a93d6aab0eaf20c7423acce23 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 10 Aug 2014 17:08:22 +0200
Subject: [PATCH 140/751] Fixed swing arm animation when you ate.
---
src/Entities/Player.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index d1d7349a6..8fa060a5d 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -601,7 +601,6 @@ void cPlayer::FinishEating(void)
// Send the packets:
m_ClientHandle->SendEntityStatus(*this, esPlayerEatingAccepted);
- m_World->BroadcastEntityAnimation(*this, 0);
m_World->BroadcastEntityMetadata(*this);
// consume the item:
@@ -619,8 +618,8 @@ void cPlayer::FinishEating(void)
// if the food is mushroom soup, return a bowl to the inventory
if (Item.m_ItemType == E_ITEM_MUSHROOM_SOUP)
{
- cItem emptyBowl(E_ITEM_BOWL, 1, 0, "");
- GetInventory().AddItem(emptyBowl, true, true);
+ cItem EmptyBowl(E_ITEM_BOWL);
+ GetInventory().AddItem(EmptyBowl, true, true);
}
}
@@ -631,7 +630,6 @@ void cPlayer::FinishEating(void)
void cPlayer::AbortEating(void)
{
m_EatingFinishTick = -1;
- m_World->BroadcastEntityAnimation(*this, 0);
m_World->BroadcastEntityMetadata(*this);
}
From 938bf1df69ae88ecdd85029d20bfd09d4fbf7618 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 10 Aug 2014 17:12:08 +0200
Subject: [PATCH 141/751] Changed comment.
---
src/Blocks/BlockSlab.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h
index 49f00c88c..e67f0e8b3 100644
--- a/src/Blocks/BlockSlab.h
+++ b/src/Blocks/BlockSlab.h
@@ -119,9 +119,7 @@ public:
return;
}
- /* Sends the slab back to the client.
- The normal back sending adds the block face to the locations, but this don't work because the Y-Coordinate with the block face
- is one higher than the real slab position. */
+ // Sends the slab back to the client. It's to refuse a doubleslab placement.
a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
From 42bad0edec58f42e4072360c52870d3be9ced3c5 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 10 Aug 2014 20:06:03 +0200
Subject: [PATCH 142/751] Added a comment and simplified code.
---
src/ClientHandle.cpp | 9 +++------
src/World.cpp | 7 ++-----
2 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 286c17513..37d7edbc1 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -341,15 +341,12 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
m_Protocol->SendWeather(World->GetWeather());
}
- // Send time
+ // Send time:
Int64 TimeOfDay = World->GetTimeOfDay();
if (!World->IsDaylightCycleEnabled())
{
- TimeOfDay *= -1;
- if (TimeOfDay == 0)
- {
- TimeOfDay = -1;
- }
+ // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
+ TimeOfDay = std::min(-TimeOfDay, -1);
}
m_Protocol->SendTimeUpdate(World->GetWorldAge(), TimeOfDay);
diff --git a/src/World.cpp b/src/World.cpp
index 0ae7f80a6..dcca0519e 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2253,11 +2253,8 @@ void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
int TimeOfDay = m_TimeOfDay;
if (!m_IsDaylightCycleEnabled)
{
- TimeOfDay *= -1;
- if (TimeOfDay == 0)
- {
- TimeOfDay = -1;
- }
+ // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
+ TimeOfDay = std::min(-TimeOfDay, -1);
}
cCSLock Lock(m_CSPlayers);
From 806d0936dc94f235858ffe1772a6215f86c5d000 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 10 Aug 2014 19:34:11 +0100
Subject: [PATCH 143/751] First Implementatation of new Loggin framework
---
SetFlags.cmake | 2 +
src/Bindings/LuaFunctions.h | 2 +-
src/Bindings/ManualBindings.cpp | 10 +-
src/CMakeLists.txt | 6 +-
src/CompositeChat.cpp | 24 +--
src/CompositeChat.h | 2 +-
src/Globals.h | 2 +-
src/MCLogger.cpp | 267 --------------------------------
src/MCLogger.h | 95 ------------
src/OSSupport/File.cpp | 5 +-
src/OSSupport/File.h | 3 +-
src/Root.cpp | 26 +++-
src/Root.h | 2 -
src/StringUtils.h | 1 -
src/main.cpp | 2 +
15 files changed, 51 insertions(+), 398 deletions(-)
delete mode 100644 src/MCLogger.cpp
delete mode 100644 src/MCLogger.h
diff --git a/SetFlags.cmake b/SetFlags.cmake
index a5a61eaa4..0e2e0c277 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -1,3 +1,5 @@
+
+
macro (add_flags_lnk FLAGS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FLAGS}")
diff --git a/src/Bindings/LuaFunctions.h b/src/Bindings/LuaFunctions.h
index 2ea37d7a4..6a645ed53 100644
--- a/src/Bindings/LuaFunctions.h
+++ b/src/Bindings/LuaFunctions.h
@@ -1,6 +1,6 @@
#pragma once
-#include "../MCLogger.h"
+#include "LogDispacher.h"
#include
// tolua_begin
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 9ba1501c5..d792cd0ee 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -168,7 +168,7 @@ static AString GetLogMessage(lua_State * tolua_S)
static int tolua_LOG(lua_State * tolua_S)
{
// If the param is a cCompositeChat, read the log level from it:
- cMCLogger::eLogLevel LogLevel = cMCLogger::llRegular;
+ Logger::eLogLevel LogLevel = Logger::llRegular;
tolua_Error err;
if (tolua_isusertype(tolua_S, 1, "cCompositeChat", false, &err))
{
@@ -176,7 +176,7 @@ static int tolua_LOG(lua_State * tolua_S)
}
// Log the message:
- cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), LogLevel);
+ Logger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), LogLevel);
return 0;
}
@@ -186,7 +186,7 @@ static int tolua_LOG(lua_State * tolua_S)
static int tolua_LOGINFO(lua_State * tolua_S)
{
- cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llInfo);
+ Logger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), Logger::llInfo);
return 0;
}
@@ -196,7 +196,7 @@ static int tolua_LOGINFO(lua_State * tolua_S)
static int tolua_LOGWARN(lua_State * tolua_S)
{
- cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llWarning);
+ Logger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), Logger::llWarning);
return 0;
}
@@ -206,7 +206,7 @@ static int tolua_LOGWARN(lua_State * tolua_S)
static int tolua_LOGERROR(lua_State * tolua_S)
{
- cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llError);
+ Logger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), Logger::llError);
return 0;
}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index db9c61082..0feee4fcb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required (VERSION 2.8.2)
project (MCServer)
+
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/")
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/jsoncpp/include")
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/polarssl/include")
@@ -41,8 +42,9 @@ SET (SRCS
LightingThread.cpp
LineBlockTracer.cpp
LinearInterpolation.cpp
+ Listeners.cpp
Log.cpp
- MCLogger.cpp
+ LogDispacher.cpp
Map.cpp
MapManager.cpp
MobCensus.cpp
@@ -108,7 +110,7 @@ SET (HDRS
LinearInterpolation.h
LinearUpscale.h
Log.h
- MCLogger.h
+ LogDispacher.h
Map.h
MapManager.h
Matrix4.h
diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp
index f1a797897..b702447be 100644
--- a/src/CompositeChat.cpp
+++ b/src/CompositeChat.cpp
@@ -353,23 +353,23 @@ AString cCompositeChat::ExtractText(void) const
-cMCLogger::eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageType)
+Logger::eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageType)
{
switch (a_MessageType)
{
- case mtCustom: return cMCLogger::llRegular;
- case mtFailure: return cMCLogger::llWarning;
- case mtInformation: return cMCLogger::llInfo;
- case mtSuccess: return cMCLogger::llRegular;
- case mtWarning: return cMCLogger::llWarning;
- case mtFatal: return cMCLogger::llError;
- case mtDeath: return cMCLogger::llRegular;
- case mtPrivateMessage: return cMCLogger::llRegular;
- case mtJoin: return cMCLogger::llRegular;
- case mtLeave: return cMCLogger::llRegular;
+ case mtCustom: return Logger::llRegular;
+ case mtFailure: return Logger::llWarning;
+ case mtInformation: return Logger::llInfo;
+ case mtSuccess: return Logger::llRegular;
+ case mtWarning: return Logger::llWarning;
+ case mtFatal: return Logger::llError;
+ case mtDeath: return Logger::llRegular;
+ case mtPrivateMessage: return Logger::llRegular;
+ case mtJoin: return Logger::llRegular;
+ case mtLeave: return Logger::llRegular;
}
ASSERT(!"Unhandled MessageType");
- return cMCLogger::llError;
+ return Logger::llError;
}
diff --git a/src/CompositeChat.h b/src/CompositeChat.h
index 1ad196f1d..cc7c446c3 100644
--- a/src/CompositeChat.h
+++ b/src/CompositeChat.h
@@ -196,7 +196,7 @@ public:
/** Converts the MessageType to a LogLevel value.
Used by the logging bindings when logging a cCompositeChat object. */
- static cMCLogger::eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType);
+ static Logger::eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType);
protected:
/** All the parts that */
diff --git a/src/Globals.h b/src/Globals.h
index 60ee456c9..ae7a68e7f 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -249,7 +249,7 @@ template class SizeChecker;
#include "OSSupport/Event.h"
#include "OSSupport/Thread.h"
#include "OSSupport/File.h"
- #include "MCLogger.h"
+ #include "LogDispacher.h"
#else
// Logging functions
void inline LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);
diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp
deleted file mode 100644
index 044e83937..000000000
--- a/src/MCLogger.cpp
+++ /dev/null
@@ -1,267 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include
-#include "Log.h"
-
-
-
-
-
-cMCLogger * cMCLogger::s_MCLogger = NULL;
-
-#ifdef _WIN32
- #include // Needed for _isatty(), not available on Linux
-
- HANDLE g_Console = GetStdHandle(STD_OUTPUT_HANDLE);
- WORD g_DefaultConsoleAttrib = 0x07;
-#elif defined (__linux) && !defined(ANDROID_NDK)
- #include // Needed for isatty() on Linux
-#endif
-
-
-
-
-
-cMCLogger * cMCLogger::GetInstance(void)
-{
- return s_MCLogger;
-}
-
-
-
-
-
-cMCLogger::cMCLogger(void):
- m_ShouldColorOutput(false)
-{
- AString FileName;
- Printf(FileName, "LOG_%d.txt", (int)time(NULL));
- InitLog(FileName);
-}
-
-
-
-
-
-cMCLogger::cMCLogger(const AString & a_FileName)
-{
- InitLog(a_FileName);
-}
-
-
-
-
-
-cMCLogger::~cMCLogger()
-{
- m_Log->Log("--- Stopped Log ---\n");
- delete m_Log;
- m_Log = NULL;
- if (this == s_MCLogger)
- {
- s_MCLogger = NULL;
- }
-}
-
-
-
-
-
-void cMCLogger::InitLog(const AString & a_FileName)
-{
- m_Log = new cLog(a_FileName);
- m_Log->Log("--- Started Log ---\n");
-
- s_MCLogger = this;
-
- #ifdef _WIN32
- // See whether we are writing to a console the default console attrib:
- m_ShouldColorOutput = (_isatty(_fileno(stdin)) != 0);
- if (m_ShouldColorOutput)
- {
- CONSOLE_SCREEN_BUFFER_INFO sbi;
- GetConsoleScreenBufferInfo(g_Console, &sbi);
- g_DefaultConsoleAttrib = sbi.wAttributes;
- }
- #elif defined (__linux) && !defined(ANDROID_NDK)
- m_ShouldColorOutput = isatty(fileno(stdout));
- // TODO: Check if the terminal supports colors, somehow?
- #endif
-}
-
-
-
-
-
-void cMCLogger::LogSimple(const char * a_Text, eLogLevel a_LogLevel)
-{
- switch (a_LogLevel)
- {
- case llRegular:
- {
- LOG("%s", a_Text);
- break;
- }
- case llInfo:
- {
- LOGINFO("%s", a_Text);
- break;
- }
- case llWarning:
- {
- LOGWARN("%s", a_Text);
- break;
- }
- case llError:
- {
- LOGERROR("%s", a_Text);
- break;
- }
- }
-}
-
-
-
-
-
-void cMCLogger::Log(const char * a_Format, va_list a_ArgList)
-{
- cCSLock Lock(m_CriticalSection);
- SetColor(csRegular);
- m_Log->Log(a_Format, a_ArgList);
- ResetColor();
- puts("");
-}
-
-
-
-
-
-void cMCLogger::Info(const char * a_Format, va_list a_ArgList)
-{
- cCSLock Lock(m_CriticalSection);
- SetColor(csInfo);
- m_Log->Log(a_Format, a_ArgList);
- ResetColor();
- puts("");
-}
-
-
-
-
-
-void cMCLogger::Warn(const char * a_Format, va_list a_ArgList)
-{
- cCSLock Lock(m_CriticalSection);
- SetColor(csWarning);
- m_Log->Log(a_Format, a_ArgList);
- ResetColor();
- puts("");
-}
-
-
-
-
-
-void cMCLogger::Error(const char * a_Format, va_list a_ArgList)
-{
- cCSLock Lock(m_CriticalSection);
- SetColor(csError);
- m_Log->Log(a_Format, a_ArgList);
- ResetColor();
- puts("");
-}
-
-
-
-
-
-void cMCLogger::SetColor(eColorScheme a_Scheme)
-{
- if (!m_ShouldColorOutput)
- {
- return;
- }
- #ifdef _WIN32
- WORD Attrib = 0x07; // by default, gray on black
- switch (a_Scheme)
- {
- case csRegular: Attrib = 0x07; break; // Gray on black
- case csInfo: Attrib = 0x0e; break; // Yellow on black
- case csWarning: Attrib = 0x0c; break; // Read on black
- case csError: Attrib = 0xc0; break; // Black on red
- default: ASSERT(!"Unhandled color scheme");
- }
- SetConsoleTextAttribute(g_Console, Attrib);
- #elif defined(__linux) && !defined(ANDROID_NDK)
- switch (a_Scheme)
- {
- case csRegular: printf("\x1b[0m"); break; // Whatever the console default is
- case csInfo: printf("\x1b[33;1m"); break; // Yellow on black
- case csWarning: printf("\x1b[31;1m"); break; // Red on black
- case csError: printf("\x1b[1;33;41;1m"); break; // Yellow on red
- default: ASSERT(!"Unhandled color scheme");
- }
- #endif
-}
-
-
-
-
-
-void cMCLogger::ResetColor(void)
-{
- if (!m_ShouldColorOutput)
- {
- return;
- }
- #ifdef _WIN32
- SetConsoleTextAttribute(g_Console, g_DefaultConsoleAttrib);
- #elif defined(__linux) && !defined(ANDROID_NDK)
- printf("\x1b[0m");
- #endif
-}
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// Global functions
-
-void LOG(const char* a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- cMCLogger::GetInstance()->Log( a_Format, argList);
- va_end(argList);
-}
-
-void LOGINFO(const char* a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- cMCLogger::GetInstance()->Info( a_Format, argList);
- va_end(argList);
-}
-
-void LOGWARN(const char* a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- cMCLogger::GetInstance()->Warn( a_Format, argList);
- va_end(argList);
-}
-
-void LOGERROR(const char* a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- cMCLogger::GetInstance()->Error( a_Format, argList);
- va_end(argList);
-}
-
-
-
-
diff --git a/src/MCLogger.h b/src/MCLogger.h
deleted file mode 100644
index aa3a52d02..000000000
--- a/src/MCLogger.h
+++ /dev/null
@@ -1,95 +0,0 @@
-
-#pragma once
-
-
-
-
-class cLog;
-
-
-
-
-
-class cMCLogger
-{
-public:
- enum eLogLevel
- {
- llRegular,
- llInfo,
- llWarning,
- llError,
- };
- // tolua_end
-
- /** Creates a logger with the default filename, "logs/LOG_.log" */
- cMCLogger(void);
-
- /** Creates a logger with the specified filename inside "logs" folder */
- cMCLogger(const AString & a_FileName);
-
- ~cMCLogger();
-
- void Log (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
- void Info (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
- void Warn (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
- void Error(const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
-
- /** Logs the simple text message at the specified log level. */
- void LogSimple(const char * a_Text, eLogLevel a_LogLevel = llRegular);
-
- static cMCLogger * GetInstance();
-private:
- enum eColorScheme
- {
- csRegular,
- csInfo,
- csWarning,
- csError,
- } ;
-
- cCriticalSection m_CriticalSection;
- cLog * m_Log;
- static cMCLogger * s_MCLogger;
- bool m_ShouldColorOutput;
-
-
- /// Sets the specified color scheme in the terminal (TODO: if coloring available)
- void SetColor(eColorScheme a_Scheme);
-
- /// Resets the color back to whatever is the default in the terminal
- void ResetColor(void);
-
- /// Common initialization for all constructors, creates a logfile with the specified name and assigns s_MCLogger to this
- void InitLog(const AString & a_FileName);
-};
-
-
-
-
-
-extern void LOG(const char* a_Format, ...) FORMATSTRING(1, 2);
-extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1, 2);
-extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1, 2);
-extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);
-
-
-
-
-
-// In debug builds, translate LOGD to LOG, otherwise leave it out altogether:
-#ifdef _DEBUG
- #define LOGD LOG
-#else
- #define LOGD(...)
-#endif // _DEBUG
-
-
-
-
-
-#define LOGWARNING LOGWARN
-
-
-
-
diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp
index ff6fb5898..af8a832f6 100644
--- a/src/OSSupport/File.cpp
+++ b/src/OSSupport/File.cpp
@@ -70,6 +70,7 @@ bool cFile::Open(const AString & iFileName, eMode iMode)
case fmRead: Mode = "rb"; break;
case fmWrite: Mode = "wb"; break;
case fmReadWrite: Mode = "rb+"; break;
+ case fmAppend: Mode = "a+"; break;
}
if (Mode == NULL)
{
@@ -255,7 +256,7 @@ int cFile::ReadRestOfFile(AString & a_Contents)
return -1;
}
- int DataSize = GetSize() - Tell();
+ size_t DataSize = GetSize() - Tell();
// HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly
a_Contents.assign((size_t)DataSize, '\0');
@@ -459,7 +460,7 @@ int cFile::Printf(const char * a_Fmt, ...)
va_start(args, a_Fmt);
AppendVPrintf(buf, a_Fmt, args);
va_end(args);
- return Write(buf.c_str(), (int)buf.length());
+ return Write(buf.c_str(), buf.length());
}
diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h
index 2a7ecf0ed..8891511c4 100644
--- a/src/OSSupport/File.h
+++ b/src/OSSupport/File.h
@@ -62,7 +62,8 @@ public:
{
fmRead, // Read-only. If the file doesn't exist, object will not be valid
fmWrite, // Write-only. If the file already exists, it will be overwritten
- fmReadWrite // Read/write. If the file already exists, it will be left intact; writing will overwrite the data from the beginning
+ fmReadWrite, // Read/write. If the file already exists, it will be left intact; writing will overwrite the data from the beginning
+ fmAppend // Write-only. If the file already exists cursor will be moved to the end of the file
} ;
/** Simple constructor - creates an unopened file object, use Open() to open / create a real file */
diff --git a/src/Root.cpp b/src/Root.cpp
index c20cf0d21..72048b631 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -18,6 +18,7 @@
#include "CommandOutput.h"
#include "DeadlockDetect.h"
#include "OSSupport/Timer.h"
+#include "Listeners.h"
#include "inifile/iniFile.h"
@@ -51,7 +52,6 @@ cRoot::cRoot(void) :
m_FurnaceRecipe(NULL),
m_WebAdmin(NULL),
m_PluginManager(NULL),
- m_Log(NULL),
m_bStop(false),
m_bRestart(false)
{
@@ -105,10 +105,15 @@ void cRoot::Start(void)
HMENU hmenu = GetSystemMenu(hwnd, FALSE);
EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); // Disable close button when starting up; it causes problems with our CTRL-CLOSE handling
#endif
+
+ Logger::cLoggerListener * consoleLogListener = Logger::MakeConsoleListener();
+ Logger::cLoggerListener * fileLogListener = new Logger::cFileListener();
+ Logger::GetInstance().AttachListener(consoleLogListener);
+ Logger::GetInstance().AttachListener(fileLogListener);
+
+ LOG("--- Started Log ---\n");
cDeadlockDetect dd;
- delete m_Log;
- m_Log = new cMCLogger();
m_bStop = false;
while (!m_bStop)
@@ -249,8 +254,13 @@ void cRoot::Start(void)
delete m_Server; m_Server = NULL;
LOG("Shutdown successful!");
}
-
- delete m_Log; m_Log = NULL;
+
+ LOG("--- Stopped Log ---");
+
+ Logger::GetInstance().DetachListener(consoleLogListener);
+ delete consoleLogListener;
+ Logger::GetInstance().DetachListener(fileLogListener);
+ delete fileLogListener;
}
@@ -274,15 +284,15 @@ void cRoot::LoadWorlds(cIniFile & IniFile)
m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld;
// Then load the other worlds
- unsigned int KeyNum = IniFile.FindKey("Worlds");
- unsigned int NumWorlds = IniFile.GetNumValues(KeyNum);
+ int KeyNum = IniFile.FindKey("Worlds");
+ int NumWorlds = IniFile.GetNumValues(KeyNum);
if (NumWorlds <= 0)
{
return;
}
bool FoundAdditionalWorlds = false;
- for (unsigned int i = 0; i < NumWorlds; i++)
+ for (int i = 0; i < NumWorlds; i++)
{
AString ValueName = IniFile.GetValueName(KeyNum, i);
if (ValueName.compare("World") != 0)
diff --git a/src/Root.h b/src/Root.h
index 1cd175ab4..6840efcbe 100644
--- a/src/Root.h
+++ b/src/Root.h
@@ -196,8 +196,6 @@ private:
cMojangAPI m_MojangAPI;
cHTTPServer m_HTTPServer;
- cMCLogger * m_Log;
-
bool m_bStop;
bool m_bRestart;
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 142aaf59b..3d4379352 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -12,7 +12,6 @@
-
typedef std::string AString;
typedef std::vector AStringVector;
typedef std::list AStringList;
diff --git a/src/main.cpp b/src/main.cpp
index 106233342..e40035538 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -273,6 +273,8 @@ int main( int argc, char **argv)
}
} // for i - argv[]
+ Logger::InitiateMultithreading();
+
#if !defined(ANDROID_NDK)
try
#endif
From bf0050e066af60b5f4060b298118d74cf84dc299 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 10 Aug 2014 19:44:49 +0100
Subject: [PATCH 144/751] Added forgoten files
---
src/Listeners.cpp | 236 +++++++++++++++++++++++++++++++++++++++++++
src/Listeners.h | 21 ++++
src/LogDispacher.cpp | 115 +++++++++++++++++++++
src/LogDispacher.h | 85 ++++++++++++++++
4 files changed, 457 insertions(+)
create mode 100644 src/Listeners.cpp
create mode 100644 src/Listeners.h
create mode 100644 src/LogDispacher.cpp
create mode 100644 src/LogDispacher.h
diff --git a/src/Listeners.cpp b/src/Listeners.cpp
new file mode 100644
index 000000000..384dcaf91
--- /dev/null
+++ b/src/Listeners.cpp
@@ -0,0 +1,236 @@
+
+#include "Globals.h"
+
+#include "Listeners.h"
+
+#if defined(_WIN32)
+ #include // Needed for _isatty(), not available on Linux
+#elif defined(__linux) && !defined(ANDROID_NDK)
+ #include // Needed for isatty() on Linux
+#elif defined(ANDROID_NDK)
+ #include
+#endif
+
+
+namespace Logger
+{
+
+ #if defined(_WIN32) || (defined (__linux) && !defined(ANDROID_NDK))
+ class cColouredConsoleListener
+ : public cLoggerListener
+ {
+
+ virtual void SetLogColour(eLogLevel a_LogLevel) = 0;
+ virtual void SetDefaultLogColour() = 0;
+
+ virtual void Log(AString a_Message, eLogLevel a_LogLevel) override
+ {
+ SetLogColour(a_LogLevel);
+ puts(a_Message.c_str());
+ SetDefaultLogColour();
+ }
+ };
+ #endif
+
+ #ifdef _WIN32
+ class cWindowsConsoleListener
+ : public cColouredConsoleListener
+ {
+ public:
+ cWindowsConsoleListener(HANDLE a_Console, WORD a_DefaultConsoleAttrib) :
+ m_Console(a_Console),
+ m_DefaultConsoleAttrib(a_DefaultConsoleAttrib)
+ {
+ }
+
+ #ifdef DEBUG
+ virtual void Log(AString a_Message, eLogLevel a_LogLevel) override
+ {
+ cColouredConsoleListener::Log(a_Message, a_LogLevel);
+ // In a Windows Debug build, output the log to debug console as well:
+ OutputDebugStringA(a_Message.c_str());
+ }
+ #endif // _WIN32
+
+
+ virtual void SetLogColour(eLogLevel a_LogLevel) override
+ {
+ // by default, gray on black
+ WORD Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
+ switch (a_LogLevel)
+ {
+ case llRegular:
+ // Gray on black
+ Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
+ break;
+ case llInfo:
+ // Yellow on black
+ Attrib = FOREGROUND_GREEN | ;
+ break;
+ case llWarning:
+ // Red on black
+ Attrib = FOREGROUND_RED | FOREGROUND_INTENSITY;
+ break;
+ case llError:
+ // Black on red
+ Attrib = BACKGROUND_RED | BACKGROUND_INTENSITY;
+ break;
+ }
+ SetConsoleTextAttribute(m_Console, Attrib);
+ }
+ virtual void SetDefaultLogColour() override
+ {
+ SetConsoleTextAttribute(m_Console, m_DefaultConsoleAttrib);
+ }
+ private:
+ HANDLE m_Console;
+ WORD m_DefaultConsoleAttrib;
+ };
+ #elif defined (__linux) && !defined(ANDROID_NDK)
+ class cLinuxConsoleListener
+ : public cColouredConsoleListener
+ {
+ public:
+ virtual void SetLogColour(eLogLevel a_LogLevel) override
+ {
+ switch (a_LogLevel)
+ {
+ case llRegular:
+ // Whatever the console default is
+ printf("\x1b[0m");
+ break;
+ case llInfo:
+ // Yellow on black
+ printf("\x1b[33;1m");
+ break;
+ case llWarning:
+ // Red on black
+ printf("\x1b[31;1m");
+ break;
+ case llError:
+ // Yellow on red
+ printf("\x1b[1;33;41;1m");
+ break;
+ }
+ }
+ virtual void SetDefaultLogColour() override
+ {
+ // Whatever the console default is
+ printf("\x1b[0m");
+ }
+ };
+ #elif defined(ANDROID_NDK)
+ class cAndroidConsoleListener
+ : public cLoggerListener
+ {
+ public:
+ virtual void Log(AString a_Message, eLogLevel a_LogLevel) override
+ {
+ android_LogPriority AndroidLogLevel;
+ switch (a_LogLevel)
+ {
+ case llRegular:
+ AndroidLogLevel = ANDROID_LOG_VERBOSE;
+ break;
+ case llInfo:
+ AndroidLogLevel = ANDROID_LOG_INFO;
+ break;
+ case llWarning:
+ AndroidLogLevel = ANDROID_LOG_WARNING;
+ break;
+ case llError:
+ AndroidLogLevel = ANDROID_LOG_ERROR;
+ break;
+ }
+ __android_log_print(AndroidLogLevel, "MCServer", "%s", a_Message.c_str());
+ }
+ };
+ #endif
+
+ class cVanillaCPPConsoleListener
+ : public cLoggerListener
+ {
+ public:
+ virtual void Log(AString a_Message, eLogLevel a_LogLevel) override
+ {
+ AString LogLevelString;
+ switch (a_LogLevel)
+ {
+ case llRegular:
+ LogLevelString = "Log";
+ break;
+ case llInfo:
+ LogLevelString = "Info";
+ break;
+ case llWarning:
+ LogLevelString = "Warning";
+ break;
+ case llError:
+ LogLevelString = "Error";
+ break;
+ }
+ printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
+ }
+ };
+
+
+
+ cLoggerListener * MakeConsoleListener()
+ {
+ #ifdef _WIN32
+ // See whether we are writing to a console the default console attrib:
+ bool ShouldColorOutput = (_isatty(_fileno(stdin)) != 0);
+ if (ShouldColorOutput)
+ {
+ CONSOLE_SCREEN_BUFFER_INFO sbi;
+ HANDLE Console = getStdHandle(STD_OUTPUT_HANDLE);
+ GetConsoleScreenBufferInfo(Console, &sbi);
+ WORD DefaultConsoleAttrib = sbi.wAttributes;
+ return new cWindowsConsoleListener(Console, DefaultConsoleAttrib);
+ } else {
+ return new cVanillaCPPConsoleListener();
+ }
+
+ #elif defined (__linux) && !defined(ANDROID_NDK)
+ // TODO: lookup terminal in terminfo
+ if (isatty(fileno(stdout)))
+ {
+ return new cLinuxConsoleListener();
+ } else {
+ return new cVanillaCPPConsoleListener();
+ }
+ #else
+ return new cVanillaCPPConsoleListener();
+ #endif
+ }
+
+ cFileListener::cFileListener()
+ {
+ cFile::CreateFolder(FILE_IO_PREFIX + AString("logs"));
+ AString FileName;
+ FileName = Printf("%s%sLOG_%d.txt", FILE_IO_PREFIX, "logs/", (int)time(NULL));
+ m_File.Open(FileName, cFile::fmAppend);
+ }
+
+ void cFileListener::Log(AString a_Message, eLogLevel a_LogLevel)
+ {
+ AString LogLevelString;
+ switch (a_LogLevel)
+ {
+ case llRegular:
+ LogLevelString = "Log";
+ break;
+ case llInfo:
+ LogLevelString = "Info";
+ break;
+ case llWarning:
+ LogLevelString = "Warning";
+ break;
+ case llError:
+ LogLevelString = "Error";
+ break;
+ }
+ m_File.Printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
+ }
+
+}
diff --git a/src/Listeners.h b/src/Listeners.h
new file mode 100644
index 000000000..bc29d0c06
--- /dev/null
+++ b/src/Listeners.h
@@ -0,0 +1,21 @@
+
+#include "LogDispacher.h"
+
+namespace Logger
+{
+
+ class cFileListener
+ : public cLoggerListener
+ {
+ public:
+
+ cFileListener();
+ cFileListener(AString a_Filename);
+
+ virtual void Log(AString a_Message, eLogLevel a_LogLevel) override;
+ private:
+ cFile m_File;
+ };
+
+ cLoggerListener * MakeConsoleListener();
+}
diff --git a/src/LogDispacher.cpp b/src/LogDispacher.cpp
new file mode 100644
index 000000000..337d718e6
--- /dev/null
+++ b/src/LogDispacher.cpp
@@ -0,0 +1,115 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "Log.h"
+#include "OSSupport/IsThread.h"
+
+
+
+namespace Logger
+{
+
+ cLogDispacher & GetInstance(void)
+ {
+ static cLogDispacher Instance;
+ return Instance;
+ }
+
+ void InitiateMultithreading()
+ {
+ GetInstance();
+ }
+
+ void cLogDispacher::LogSimple(AString a_Message, eLogLevel a_LogLevel)
+ {
+ time_t rawtime;
+ time ( &rawtime);
+
+ struct tm* timeinfo;
+ #ifdef _MSC_VER
+ struct tm timeinforeal;
+ timeinfo = &timeinforeal;
+ localtime_s(timeinfo, &rawtime);
+ #else
+ timeinfo = localtime( &rawtime);
+ #endif
+
+ AString Line;
+ #ifdef _DEBUG
+ Printf(Line, "[%04lx|%02d:%02d:%02d] %s\n", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ #else
+ Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ #endif
+
+
+ cCSLock Lock(m_CriticalSection);
+ for(size_t i = 0; i < m_LogListeners.size(); i++)
+ {
+ m_LogListeners[i]->Log(a_Message, a_LogLevel);
+ }
+ }
+
+
+
+
+
+ void cLogDispacher::Log(const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList)
+ {
+ AString Message;
+ AppendVPrintf(Message, a_Format, a_ArgList);
+ LogSimple(Message, a_LogLevel);
+ }
+
+ void cLogDispacher::AttachListener(Logger::cLoggerListener * a_Listener)
+ {
+ cCSLock Lock(m_CriticalSection);
+ m_LogListeners.push_back(a_Listener);
+ }
+
+ void cLogDispacher::DetachListener(Logger::cLoggerListener * a_Listener)
+ {
+ cCSLock Lock(m_CriticalSection);
+ m_LogListeners.erase(std::remove(m_LogListeners.begin(), m_LogListeners.end(), a_Listener));
+ }
+};
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Global functions
+
+void LOG(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ Logger::GetInstance().Log(a_Format, Logger::llRegular, argList);
+ va_end(argList);
+}
+
+void LOGINFO(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ Logger::GetInstance().Log( a_Format, Logger::llInfo, argList);
+ va_end(argList);
+}
+
+void LOGWARN(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ Logger::GetInstance().Log( a_Format, Logger::llWarning, argList);
+ va_end(argList);
+}
+
+void LOGERROR(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ Logger::GetInstance().Log( a_Format, Logger::llError, argList);
+ va_end(argList);
+}
+
+
+
+
diff --git a/src/LogDispacher.h b/src/LogDispacher.h
new file mode 100644
index 000000000..31b3b3fc1
--- /dev/null
+++ b/src/LogDispacher.h
@@ -0,0 +1,85 @@
+
+#pragma once
+
+
+
+class cLog;
+
+
+namespace Logger
+{
+
+ enum eLogLevel
+ {
+ llRegular,
+ llInfo,
+ llWarning,
+ llError,
+ };
+
+ class cLogDispacher;
+
+ // Must be called before calling GetInstance in a multithreaded context
+ void InitiateMultithreading();
+
+ cLogDispacher & GetInstance(void);
+
+ class cLoggerListener
+ {
+ public:
+ virtual void Log(AString a_Message, eLogLevel a_LogLevel) = 0;
+
+ virtual ~cLoggerListener(){}
+ };
+
+ class cLogDispacher
+ {
+ public:
+
+ void Log (const char * a_Format, Logger::eLogLevel a_LogLevel, va_list a_ArgList) FORMATSTRING(2, 0);
+
+ /** Logs the simple text message at the specified log level. */
+ void LogSimple(AString a_Message, Logger::eLogLevel a_LogLevel = Logger::llRegular);
+
+ void AttachListener(Logger::cLoggerListener * a_Listener);
+ void DetachListener(Logger::cLoggerListener * a_Listener);
+
+ private:
+
+ cCriticalSection m_CriticalSection;
+ std::vector m_LogListeners;
+
+ };
+
+}
+
+
+
+
+
+
+extern void LOG(const char* a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);
+
+
+
+
+
+// In debug builds, translate LOGD to LOG, otherwise leave it out altogether:
+#ifdef _DEBUG
+ #define LOGD LOG
+#else
+ #define LOGD(...)
+#endif // _DEBUG
+
+
+
+
+
+#define LOGWARNING LOGWARN
+
+
+
+
From be780b380ee91f5de27eecb3d8809506d4198534 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 10 Aug 2014 20:10:47 +0100
Subject: [PATCH 145/751] Fixed Tools to work with new logging framework
---
Tools/MCADefrag/CMakeLists.txt | 6 +-
Tools/MCADefrag/MCADefrag.cpp | 16 ++-
Tools/ProtoProxy/CMakeLists.txt | 6 +-
src/CMakeLists.txt | 2 -
src/Log.cpp | 169 --------------------------------
src/Log.h | 30 ------
src/LogDispacher.cpp | 1 -
src/LogDispacher.h | 4 -
8 files changed, 18 insertions(+), 216 deletions(-)
delete mode 100644 src/Log.cpp
delete mode 100644 src/Log.h
diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt
index 2a021049f..e237b6429 100644
--- a/Tools/MCADefrag/CMakeLists.txt
+++ b/Tools/MCADefrag/CMakeLists.txt
@@ -39,14 +39,12 @@ set_exe_flags()
set(SHARED_SRC
../../src/StringCompression.cpp
../../src/StringUtils.cpp
- ../../src/Log.cpp
- ../../src/MCLogger.cpp
+ ../../src/Listeners.cpp
+ ../../src/LogDispacher.cpp
)
set(SHARED_HDR
../../src/ByteBuffer.h
../../src/StringUtils.h
- ../../src/Log.h
- ../../src/MCLogger.h
)
flatten_files(SHARED_SRC)
flatten_files(SHARED_HDR)
diff --git a/Tools/MCADefrag/MCADefrag.cpp b/Tools/MCADefrag/MCADefrag.cpp
index a2de7f957..702b04ebf 100644
--- a/Tools/MCADefrag/MCADefrag.cpp
+++ b/Tools/MCADefrag/MCADefrag.cpp
@@ -5,7 +5,8 @@
#include "Globals.h"
#include "MCADefrag.h"
-#include "MCLogger.h"
+#include "LogDispacher.h"
+#include "Listeners.h"
#include "zlib/zlib.h"
@@ -21,7 +22,13 @@ static const Byte g_Zeroes[4096] = {0};
int main(int argc, char ** argv)
{
- new cMCLogger(Printf("Defrag_%08x.log", time(NULL)));
+ Logger::cLoggerListener * consoleLogListener = Logger::MakeConsoleListener();
+ Logger::cLoggerListener * fileLogListener = new Logger::cFileListener();
+ Logger::GetInstance().AttachListener(consoleLogListener);
+ Logger::GetInstance().AttachListener(fileLogListener);
+
+ Logger::InitiateMultithreading();
+
cMCADefrag Defrag;
if (!Defrag.Init(argc, argv))
{
@@ -30,6 +37,11 @@ int main(int argc, char ** argv)
Defrag.Run();
+ Logger::GetInstance().DetachListener(consoleLogListener);
+ delete consoleLogListener;
+ Logger::GetInstance().DetachListener(fileLogListener);
+ delete fileLogListener;
+
return 0;
}
diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt
index f0796363c..16c59bb43 100644
--- a/Tools/ProtoProxy/CMakeLists.txt
+++ b/Tools/ProtoProxy/CMakeLists.txt
@@ -34,20 +34,18 @@ set_exe_flags()
set(SHARED_SRC
../../src/ByteBuffer.cpp
../../src/StringUtils.cpp
- ../../src/Log.cpp
- ../../src/MCLogger.cpp
../../src/PolarSSL++/AesCfb128Decryptor.cpp
../../src/PolarSSL++/AesCfb128Encryptor.cpp
../../src/PolarSSL++/CryptoKey.cpp
../../src/PolarSSL++/CtrDrbgContext.cpp
../../src/PolarSSL++/EntropyContext.cpp
../../src/PolarSSL++/RsaPrivateKey.cpp
+ ../../src/Listeners.cpp
+ ../../src/LogDispacher.cpp
)
set(SHARED_HDR
../../src/ByteBuffer.h
../../src/StringUtils.h
- ../../src/Log.h
- ../../src/MCLogger.h
../../src/PolarSSL++/AesCfb128Decryptor.h
../../src/PolarSSL++/AesCfb128Encryptor.h
../../src/PolarSSL++/CryptoKey.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0feee4fcb..bca6a2eb0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -43,7 +43,6 @@ SET (SRCS
LineBlockTracer.cpp
LinearInterpolation.cpp
Listeners.cpp
- Log.cpp
LogDispacher.cpp
Map.cpp
MapManager.cpp
@@ -109,7 +108,6 @@ SET (HDRS
LineBlockTracer.h
LinearInterpolation.h
LinearUpscale.h
- Log.h
LogDispacher.h
Map.h
MapManager.h
diff --git a/src/Log.cpp b/src/Log.cpp
deleted file mode 100644
index 7686a0fb4..000000000
--- a/src/Log.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "Log.h"
-
-#include
-#include
-#include "OSSupport/IsThread.h"
-
-#if defined(ANDROID_NDK)
- #include
- #include "ToJava.h"
-#endif
-
-
-
-
-cLog* cLog::s_Log = NULL;
-
-cLog::cLog(const AString & a_FileName)
- : m_File(NULL)
-{
- s_Log = this;
-
- // create logs directory
- cFile::CreateFolder(FILE_IO_PREFIX + AString("logs"));
-
- OpenLog((FILE_IO_PREFIX + AString("logs/") + a_FileName).c_str());
-}
-
-
-
-
-
-cLog::~cLog()
-{
- CloseLog();
- s_Log = NULL;
-}
-
-
-
-
-
-cLog * cLog::GetInstance()
-{
- if (s_Log != NULL)
- {
- return s_Log;
- }
-
- new cLog("log.txt");
- return s_Log;
-}
-
-
-
-
-
-void cLog::CloseLog()
-{
- if (m_File)
- fclose (m_File);
- m_File = 0;
-}
-
-
-
-
-
-void cLog::OpenLog( const char* a_FileName)
-{
- if (m_File) fclose (m_File);
- #ifdef _MSC_VER
- fopen_s( &m_File, a_FileName, "a+");
- #else
- m_File = fopen(a_FileName, "a+");
- #endif
-}
-
-
-
-
-
-void cLog::ClearLog()
-{
- #ifdef _MSC_VER
- if (fopen_s( &m_File, "log.txt", "w") == 0)
- fclose (m_File);
- #else
- m_File = fopen("log.txt", "w");
- if (m_File)
- fclose (m_File);
- #endif
- m_File = NULL;
-}
-
-
-
-
-
-void cLog::Log(const char * a_Format, va_list argList)
-{
- AString Message;
- AppendVPrintf(Message, a_Format, argList);
-
- time_t rawtime;
- time ( &rawtime);
-
- struct tm* timeinfo;
-#ifdef _MSC_VER
- struct tm timeinforeal;
- timeinfo = &timeinforeal;
- localtime_s(timeinfo, &rawtime);
-#else
- timeinfo = localtime( &rawtime);
-#endif
-
- AString Line;
- #ifdef _DEBUG
- Printf(Line, "[%04lx|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
- #else
- Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
- #endif
- if (m_File)
- {
- fprintf(m_File, "%s\n", Line.c_str());
- fflush(m_File);
- }
-
- // Print to console:
-#if defined(ANDROID_NDK)
- // __android_log_vprint(ANDROID_LOG_ERROR, "MCServer", a_Format, argList);
- __android_log_print(ANDROID_LOG_ERROR, "MCServer", "%s", Line.c_str());
- // CallJavaFunction_Void_String(g_JavaThread, "AddToLog", Line);
-#else
- printf("%s", Line.c_str());
-#endif
-
- #if defined (_WIN32) && defined(_DEBUG)
- // In a Windows Debug build, output the log to debug console as well:
- OutputDebugStringA((Line + "\n").c_str());
- #endif // _WIN32
-}
-
-
-
-
-
-void cLog::Log(const char * a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- Log(a_Format, argList);
- va_end(argList);
-}
-
-
-
-
-
-void cLog::SimpleLog(const char * a_String)
-{
- Log("%s", a_String);
-}
-
-
-
-
diff --git a/src/Log.h b/src/Log.h
deleted file mode 100644
index dc88aa92f..000000000
--- a/src/Log.h
+++ /dev/null
@@ -1,30 +0,0 @@
-
-#pragma once
-
-
-
-
-
-class cLog
-{
-private:
- FILE * m_File;
- static cLog * s_Log;
-
-public:
- cLog(const AString & a_FileName);
- ~cLog();
- void Log(const char * a_Format, va_list argList) FORMATSTRING(2, 0);
- void Log(const char * a_Format, ...) FORMATSTRING(2, 3);
- // tolua_begin
- void SimpleLog(const char * a_String);
- void OpenLog(const char * a_FileName);
- void CloseLog();
- void ClearLog();
- static cLog* GetInstance();
-};
-
-
-
-
-
diff --git a/src/LogDispacher.cpp b/src/LogDispacher.cpp
index 337d718e6..abca6a898 100644
--- a/src/LogDispacher.cpp
+++ b/src/LogDispacher.cpp
@@ -1,7 +1,6 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-#include "Log.h"
#include "OSSupport/IsThread.h"
diff --git a/src/LogDispacher.h b/src/LogDispacher.h
index 31b3b3fc1..1472b392a 100644
--- a/src/LogDispacher.h
+++ b/src/LogDispacher.h
@@ -2,10 +2,6 @@
#pragma once
-
-class cLog;
-
-
namespace Logger
{
From 63a07b7ffc0d34beba6752c3c1f4f5771eb2c36b Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 10 Aug 2014 20:47:16 +0100
Subject: [PATCH 146/751] Fixed potential crash in Player.cpp Fixes CID 71780
If ShouldBroadcastDeathMessages is false the pointer would fall through to a
check agaist it being a player
---
src/Entities/Player.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 8fa060a5d..8667344c7 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -906,6 +906,10 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
}
GetWorld()->BroadcastChatDeath(Printf("%s %s", GetName().c_str(), DamageText.c_str()));
}
+ else if (a_TDI.Attacker == NULL) // && !m_World->ShouldBroadcastDeathMessages() by fallthrough
+ {
+ // no-op
+ }
else if (a_TDI.Attacker->IsPlayer())
{
cPlayer * Killer = (cPlayer *)a_TDI.Attacker;
From 07103ed9d7af1c37623d6c8c96ec5084938c244b Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 10 Aug 2014 21:26:28 +0100
Subject: [PATCH 147/751] Spaces
---
src/Entities/Player.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 8667344c7..608316e9a 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -906,7 +906,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
}
GetWorld()->BroadcastChatDeath(Printf("%s %s", GetName().c_str(), DamageText.c_str()));
}
- else if (a_TDI.Attacker == NULL) // && !m_World->ShouldBroadcastDeathMessages() by fallthrough
+ else if (a_TDI.Attacker == NULL) // && !m_World->ShouldBroadcastDeathMessages() by fallthrough
{
// no-op
}
From d95768d01a93a14df38f6e0e33ca180b779c5df0 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sun, 10 Aug 2014 22:36:02 +0200
Subject: [PATCH 148/751] Bunch of tweaks: Renamed Quarts to Quartz Using
const_iterator instead of iterator Used CheckBasicStyle script to find style
errors
---
src/Generating/ComposableGenerator.cpp | 14 +++++++-------
src/Generating/StructGen.cpp | 2 +-
src/Generating/StructGen.h | 14 +++++++-------
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index 58ad8fc2e..2f575fe27 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -424,13 +424,13 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{
cStructGenOreNests::OreList Ores;
- // Quarts vein
- cStructGenOreNests::OreInfo QuartsVein;
- QuartsVein.BlockType = E_BLOCK_NETHER_QUARTZ_ORE;
- QuartsVein.MaxHeight = 255;
- QuartsVein.NumNests = 80;
- QuartsVein.NestSize = 8;
- Ores.push_back(QuartsVein);
+ // Quartz vein
+ cStructGenOreNests::OreInfo QuartzVein;
+ QuartzVein.BlockType = E_BLOCK_NETHER_QUARTZ_ORE;
+ QuartzVein.MaxHeight = 255;
+ QuartzVein.NumNests = 80;
+ QuartzVein.NestSize = 8;
+ Ores.push_back(QuartzVein);
m_FinishGens.push_back(new cStructGenOreNests(Seed, Ores, E_BLOCK_NETHERRACK));
diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp
index 1a43f2b2e..731324b0d 100644
--- a/src/Generating/StructGen.cpp
+++ b/src/Generating/StructGen.cpp
@@ -276,7 +276,7 @@ void cStructGenOreNests::GenFinish(cChunkDesc & a_ChunkDesc)
int seq = 1;
// Generate the ores from the ore list.
- for (OreList::iterator itr = m_OreList.begin(); itr != m_OreList.end(); ++itr)
+ for (OreList::const_iterator itr = m_OreList.begin(); itr != m_OreList.end(); ++itr)
{
GenerateOre(ChunkX, ChunkZ, itr->BlockType, itr->MaxHeight, itr->NumNests, itr->NestSize, BlockTypes, seq);
seq++;
diff --git a/src/Generating/StructGen.h b/src/Generating/StructGen.h
index e2fe8bc1a..55d5bc1c7 100644
--- a/src/Generating/StructGen.h
+++ b/src/Generating/StructGen.h
@@ -78,16 +78,16 @@ class cStructGenOreNests :
public:
struct OreInfo
{
- BLOCKTYPE BlockType; // The type of the nest.
- int MaxHeight; // The highest possible a nest can occur
- int NumNests; // How many nests per chunk
- int NestSize; // The amount of blocks a nest can have.
+ BLOCKTYPE BlockType; // The type of the nest.
+ int MaxHeight; // The highest possible a nest can occur
+ int NumNests; // How many nests per chunk
+ int NestSize; // The amount of blocks a nest can have.
};
typedef std::vector OreList;
- cStructGenOreNests(int a_Seed, OreList a_OreList, BLOCKTYPE a_ToReplace) :
- m_Noise(a_Seed),
+ cStructGenOreNests(int a_Seed, OreList a_OreList, BLOCKTYPE a_ToReplace) :
+ m_Noise(a_Seed),
m_Seed(a_Seed),
m_OreList(a_OreList),
m_ToReplace(a_ToReplace)
@@ -97,7 +97,7 @@ protected:
cNoise m_Noise;
int m_Seed;
- OreList m_OreList; // A list of possible ores.
+ OreList m_OreList; // A list of possible ores.
BLOCKTYPE m_ToReplace;
// cFinishGen override:
From 5623a045f598a068a7bae77cc3acad62f6160452 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 10 Aug 2014 22:06:56 +0100
Subject: [PATCH 149/751] Fixed potential null dereference Fixes CID 70466
---
src/BlockEntities/HopperEntity.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp
index 48d3b8dcc..88e7b8e1b 100644
--- a/src/BlockEntities/HopperEntity.cpp
+++ b/src/BlockEntities/HopperEntity.cpp
@@ -549,13 +549,13 @@ bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_Sl
bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ)
{
// Try the chest directly connected to the hopper:
- cChestEntity * Chest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ);
- if (Chest == NULL)
+ cChestEntity * ConnectedChest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ);
+ if (ConnectedChest == NULL)
{
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ);
return false;
}
- if (MoveItemsToGrid(*Chest))
+ if (MoveItemsToGrid(*ConnectedChest))
{
// Chest block directly connected was not full
return true;
@@ -586,13 +586,13 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
}
BLOCKTYPE Block = Neighbor->GetBlock(x, a_BlockY, z);
- if (Block != Chest->GetBlockType())
+ if (Block != ConnectedChest->GetBlockType())
{
// Not the same kind of chest
continue;
}
- Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z);
+ cChestEntity * Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z);
if (Chest == NULL)
{
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z);
From df96f437a3802ffeb36c1fefca3d2674bbb94079 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 10 Aug 2014 22:15:52 +0100
Subject: [PATCH 150/751] Fixed circular dependecy luaState_Call.inc
---
src/Bindings/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt
index a2b381a26..54152668a 100644
--- a/src/Bindings/CMakeLists.txt
+++ b/src/Bindings/CMakeLists.txt
@@ -45,7 +45,6 @@ set(BINDING_DEPENDENCIES
../Bindings/AllToLua.pkg
../Bindings/gen_LuaState_Call.lua
../Bindings/LuaFunctions.h
- ../Bindings/LuaState_Call.inc
../Bindings/LuaWindow.h
../Bindings/Plugin.h
../Bindings/PluginLua.h
@@ -128,6 +127,7 @@ if (NOT MSVC)
endif ()
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES GENERATED TRUE)
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.h PROPERTIES GENERATED TRUE)
+set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/LuaState_Call.inc PROPERTIES GENERATED TRUE)
if(NOT MSVC)
add_library(Bindings ${SRCS} ${HDRS})
From dba672361164dc5dc5f94d24bde3176c7de89d4c Mon Sep 17 00:00:00 2001
From: archshift
Date: Sat, 2 Aug 2014 22:42:53 -0700
Subject: [PATCH 151/751] Player.cpp: change unnamed enum to constant integers
---
src/Entities/Player.cpp | 2 +-
src/Entities/Player.h | 13 +++++++------
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 608316e9a..91bcddca3 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -509,7 +509,7 @@ void cPlayer::Heal(int a_Health)
void cPlayer::SetFoodLevel(int a_FoodLevel)
{
- int FoodLevel = std::max(0, std::min(a_FoodLevel, (int)MAX_FOOD_LEVEL));
+ int FoodLevel = Clamp(a_FoodLevel, 0, MAX_FOOD_LEVEL);
if (cRoot::Get()->GetPluginManager()->CallHookPlayerFoodLevelChange(*this, FoodLevel))
{
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index e26808bfc..f345a0207 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -29,12 +29,13 @@ class cPlayer :
typedef cPawn super;
public:
- enum
- {
- MAX_HEALTH = 20,
- MAX_FOOD_LEVEL = 20,
- EATING_TICKS = 30, ///< Number of ticks it takes to eat an item
- } ;
+ static const int MAX_HEALTH = 20;
+
+ static const int MAX_FOOD_LEVEL = 20;
+
+ /** Number of ticks it takes to eat an item */
+ static const int EATING_TICKS = 30;
+
// tolua_end
CLASS_PROTODEF(cPlayer)
From 92f67789fc24572092a70d582aef22d7ef1dd272 Mon Sep 17 00:00:00 2001
From: archshift
Date: Sat, 2 Aug 2014 22:56:08 -0700
Subject: [PATCH 152/751] Gave names to unnamed enums
---
src/Enchantments.h | 2 +-
src/HTTPServer/HTTPMessage.h | 2 +-
src/Inventory.h | 4 ++--
src/Protocol/Protocol125.h | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/Enchantments.h b/src/Enchantments.h
index 98d7c0d36..824f6aa55 100644
--- a/src/Enchantments.h
+++ b/src/Enchantments.h
@@ -43,7 +43,7 @@ public:
/** Individual enchantment IDs, corresponding to their NBT IDs: http://www.minecraftwiki.net/wiki/Data_Values#Enchantment_IDs
*/
- enum
+ enum eEnchantment
{
enchProtection = 0,
enchFireProtection = 1,
diff --git a/src/HTTPServer/HTTPMessage.h b/src/HTTPServer/HTTPMessage.h
index e402c8ad6..c0667030f 100644
--- a/src/HTTPServer/HTTPMessage.h
+++ b/src/HTTPServer/HTTPMessage.h
@@ -18,7 +18,7 @@
class cHTTPMessage
{
public:
- enum
+ enum eStatus
{
HTTP_OK = 200,
HTTP_BAD_REQUEST = 400,
diff --git a/src/Inventory.h b/src/Inventory.h
index ed134aee4..5628fb0da 100644
--- a/src/Inventory.h
+++ b/src/Inventory.h
@@ -39,8 +39,8 @@ public:
enum
{
invArmorCount = 4,
- invInventoryCount = 9 * 3,
- invHotbarCount = 9,
+ invInventoryCount = 9 * 3,
+ invHotbarCount = 9,
invArmorOffset = 0,
invInventoryOffset = invArmorOffset + invArmorCount,
diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h
index 18efeb079..3adac3055 100644
--- a/src/Protocol/Protocol125.h
+++ b/src/Protocol/Protocol125.h
@@ -103,7 +103,7 @@ public:
protected:
/// Results of packet-parsing:
- enum
+ enum eParseResult
{
PARSE_OK = 1,
PARSE_ERROR = -1,
From 47c928cab7d1ff73e50925bc7ef50586b6ec9821 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 11 Aug 2014 00:20:28 +0200
Subject: [PATCH 153/751] Exported daylight cycle flag to the protocol.
---
src/ClientHandle.cpp | 12 +++---------
src/ClientHandle.h | 2 +-
src/Protocol/Protocol.h | 2 +-
src/Protocol/Protocol125.cpp | 5 ++++-
src/Protocol/Protocol125.h | 2 +-
src/Protocol/Protocol14x.cpp | 8 +++++++-
src/Protocol/Protocol14x.h | 2 +-
src/Protocol/Protocol17x.cpp | 7 ++++++-
src/Protocol/Protocol17x.h | 2 +-
src/Protocol/ProtocolRecognizer.cpp | 4 ++--
src/Protocol/ProtocolRecognizer.h | 2 +-
src/World.cpp | 9 +--------
12 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 37d7edbc1..d386f3576 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -342,13 +342,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
}
// Send time:
- Int64 TimeOfDay = World->GetTimeOfDay();
- if (!World->IsDaylightCycleEnabled())
- {
- // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
- TimeOfDay = std::min(-TimeOfDay, -1);
- }
- m_Protocol->SendTimeUpdate(World->GetWorldAge(), TimeOfDay);
+ m_Protocol->SendTimeUpdate(World->GetWorldAge(), World->GetTimeOfDay(), World->IsDaylightCycleEnabled());
// Send contents of the inventory window
m_Protocol->SendWholeInventory(*m_Player->GetWindow());
@@ -2595,9 +2589,9 @@ void cClientHandle::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ)
-void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay)
+void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
{
- m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay);
+ m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay, a_DoDaylightCycle);
}
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 1bf397ad2..7ae70a07f 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -179,7 +179,7 @@ public:
void SendTabCompletionResults(const AStringVector & a_Results);
void SendTeleportEntity (const cEntity & a_Entity);
void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
- void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay); // tolua_export
+ void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle); // tolua_export
void SendUnloadChunk (int a_ChunkX, int a_ChunkZ);
void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity);
void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index d110f2af9..8e1842ec1 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -116,7 +116,7 @@ public:
virtual void SendTabCompletionResults(const AStringVector & a_Results) = 0;
virtual void SendTeleportEntity (const cEntity & a_Entity) = 0;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) = 0;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) = 0;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) = 0;
virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) = 0;
virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0;
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 538d31642..a66c64309 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1072,8 +1072,11 @@ void cProtocol125::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ)
-void cProtocol125::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay)
+void cProtocol125::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
{
+ // This protocol doesn't support a_DoDaylightCycle on false.
+ UNUSED(a_DoDaylightCycle);
+
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_UPDATE_TIME);
// Use a_WorldAge for daycount, and a_TimeOfDay for the proper time of day:
diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h
index 18efeb079..0973bb005 100644
--- a/src/Protocol/Protocol125.h
+++ b/src/Protocol/Protocol125.h
@@ -88,7 +88,7 @@ public:
virtual void SendTabCompletionResults(const AStringVector & a_Results) override;
virtual void SendTeleportEntity (const cEntity & a_Entity) override;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override {}
virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp
index 8b177ea48..3b6b6a42a 100644
--- a/src/Protocol/Protocol14x.cpp
+++ b/src/Protocol/Protocol14x.cpp
@@ -130,8 +130,14 @@ void cProtocol142::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src
-void cProtocol142::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay)
+void cProtocol142::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
{
+ if (!a_DoDaylightCycle)
+ {
+ // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
+ a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
+ }
+
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_UPDATE_TIME);
WriteInt64(a_WorldAge);
diff --git a/src/Protocol/Protocol14x.h b/src/Protocol/Protocol14x.h
index ca497bbc1..227cc8cc7 100644
--- a/src/Protocol/Protocol14x.h
+++ b/src/Protocol/Protocol14x.h
@@ -34,7 +34,7 @@ public:
// Sending commands (alphabetically sorted):
virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
virtual void SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
// Specific packet parsers:
virtual int ParseLocaleViewDistance(void) override;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 318342f09..a724133fc 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1286,9 +1286,14 @@ void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ)
-void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay)
+void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
{
ASSERT(m_State == 3); // In game mode?
+ if (!a_DoDaylightCycle)
+ {
+ // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
+ a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
+ }
cPacketizer Pkt(*this, 0x03);
Pkt.WriteInt64(a_WorldAge);
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index 9c9f563e0..ccfa19eb6 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -120,7 +120,7 @@ public:
virtual void SendTabCompletionResults(const AStringVector & a_Results) override;
virtual void SendTeleportEntity (const cEntity & a_Entity) override;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override;
virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index a7fb7bcc2..18694572a 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -716,10 +716,10 @@ void cProtocolRecognizer::SendThunderbolt(int a_BlockX, int a_BlockY, int a_Bloc
-void cProtocolRecognizer::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay)
+void cProtocolRecognizer::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
{
ASSERT(m_Protocol != NULL);
- m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay);
+ m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay, a_DoDaylightCycle);
}
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index 65829ef73..28572a8fd 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -123,7 +123,7 @@ public:
virtual void SendTabCompletionResults(const AStringVector & a_Results) override;
virtual void SendTeleportEntity (const cEntity & a_Entity) override;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override;
virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
diff --git a/src/World.cpp b/src/World.cpp
index dcca0519e..5298f3b03 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2250,13 +2250,6 @@ void cWorld::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, cons
void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
{
- int TimeOfDay = m_TimeOfDay;
- if (!m_IsDaylightCycleEnabled)
- {
- // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
- TimeOfDay = std::min(-TimeOfDay, -1);
- }
-
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
@@ -2265,7 +2258,7 @@ void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
{
continue;
}
- ch->SendTimeUpdate(m_WorldAge, TimeOfDay);
+ ch->SendTimeUpdate(m_WorldAge, m_TimeOfDay, m_IsDaylightCycleEnabled);
}
}
From a7eb4032ee32f8299857ccdfc4ad9f45227abb05 Mon Sep 17 00:00:00 2001
From: archshift
Date: Sun, 10 Aug 2014 17:13:14 -0700
Subject: [PATCH 154/751] Fixed tolua error with static initialization
---
src/Entities/Player.cpp | 9 +++++++++
src/Entities/Player.h | 6 +++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 91bcddca3..4398a5bf3 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -33,6 +33,15 @@
+const int cPlayer::MAX_HEALTH = 20;
+
+const int cPlayer::MAX_FOOD_LEVEL = 20;
+
+/** Number of ticks it takes to eat an item */
+const int cPlayer::EATING_TICKS = 30;
+
+
+
cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) :
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index f345a0207..d3ed1ef9d 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -29,12 +29,12 @@ class cPlayer :
typedef cPawn super;
public:
- static const int MAX_HEALTH = 20;
+ static const int MAX_HEALTH;
- static const int MAX_FOOD_LEVEL = 20;
+ static const int MAX_FOOD_LEVEL;
/** Number of ticks it takes to eat an item */
- static const int EATING_TICKS = 30;
+ static const int EATING_TICKS;
// tolua_end
From 202a0d1c1d6de6cc1b229026d0304a736a1d9b75 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 11 Aug 2014 14:24:36 +0200
Subject: [PATCH 155/751] Fixed cancelled fire interact from all directions.
---
src/ClientHandle.cpp | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 3e046f38d..8eff45cf4 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -920,9 +920,13 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
)
{
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))->IsClickedThrough())
+ if (a_BlockFace != BLOCK_FACE_NONE)
{
- m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player);
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+ if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY, a_BlockZ))->IsClickedThrough())
+ {
+ m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ }
}
return;
}
@@ -932,9 +936,13 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
{
// A plugin doesn't agree with the action, replace the block on the client and quit:
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))->IsClickedThrough())
+ if (a_BlockFace != BLOCK_FACE_NONE)
{
- m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player);
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+ if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY, a_BlockZ))->IsClickedThrough())
+ {
+ m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ }
}
return;
}
From 0a52ed6eb97ca5cc08fe255bfd04f78b4ea19a7e Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 11 Aug 2014 15:33:20 +0200
Subject: [PATCH 156/751] cProtocol172: Check return values.
Fixes CID 43489, CID 43490, CID 43491, CID 43493, CID 66410, CID 66411, CID 66416, CID 66417, CID 66418, CID 66419, CID 66420, CID 66421, CID 66422, CID 66423, CID 66424, CID 66425, CID 66429, CID 66430, CID 66431
---
src/Protocol/Protocol17x.cpp | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 318342f09..1f8ca00bb 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -48,7 +48,10 @@ Implements the 1.7.x protocol classes:
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
Type Var; \
- ByteBuf.Proc(Var);
+ if (!ByteBuf.Proc(Var))\
+ {\
+ return;\
+ }
@@ -1700,8 +1703,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
void cProtocol172::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer)
{
- Int64 Timestamp;
- a_ByteBuffer.ReadBEInt64(Timestamp);
+ HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp);
cPacketizer Pkt(*this, 0x01); // Ping packet
Pkt.WriteInt64(Timestamp);
@@ -2054,7 +2056,10 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel);
HANDLE_READ(a_ByteBuffer, ReadBEShort, short, Length);
AString Data;
- a_ByteBuffer.ReadString(Data, Length);
+ if (!a_ByteBuffer.ReadString(Data, Length))
+ {
+ return;
+ }
m_Client->HandlePluginMessage(Channel, Data);
}
From e0b45c189328d668f5177e529abe99387fc49cf3 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 11 Aug 2014 16:06:40 +0200
Subject: [PATCH 157/751] Fixed unchecked return values.
---
src/Bindings/ManualBindings_RankManager.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/Bindings/ManualBindings_RankManager.cpp b/src/Bindings/ManualBindings_RankManager.cpp
index d17672dcb..b109b0097 100644
--- a/src/Bindings/ManualBindings_RankManager.cpp
+++ b/src/Bindings/ManualBindings_RankManager.cpp
@@ -57,8 +57,8 @@ static int tolua_cRankManager_AddGroupToRank(lua_State * L)
S.GetStackValues(2, GroupName, RankName);
// Add the group to the rank:
- cRoot::Get()->GetRankManager().AddGroupToRank(GroupName, RankName);
- return 0;
+ S.Push(cRoot::Get()->GetRankManager().AddGroupToRank(GroupName, RankName));
+ return 1;
}
@@ -287,7 +287,10 @@ static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State * L)
// Get the permissions:
AString MsgPrefix, MsgSuffix, MsgNameColorCode;
- cRoot::Get()->GetRankManager().GetPlayerMsgVisuals(PlayerUUID, MsgPrefix, MsgSuffix, MsgNameColorCode);
+ if (!cRoot::Get()->GetRankManager().GetPlayerMsgVisuals(PlayerUUID, MsgPrefix, MsgSuffix, MsgNameColorCode))
+ {
+ return 0;
+ }
// Push the results:
S.Push(MsgPrefix);
From f7726317c9c1c27fa3d0b9b7c2df35ffff6f1f1a Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Mon, 11 Aug 2014 18:57:41 +0200
Subject: [PATCH 158/751] Add entry for bat in monsters.ini
---
MCServer/monsters.ini | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/MCServer/monsters.ini b/MCServer/monsters.ini
index d29b01d8f..c4bc8c810 100644
--- a/MCServer/monsters.ini
+++ b/MCServer/monsters.ini
@@ -185,4 +185,10 @@ AttackDamage=6.0
SightDistance=25.0
MaxHealth=100
+[Bat]
+AttackRange=2.0
+AttackRate=1
+AttackDamage=0.0
+SightDistance=25.0
+MaxHealth=6
From 74fabb079c710ab9f81e0b7ee30a8a3e3604595c Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 11 Aug 2014 22:34:33 +0200
Subject: [PATCH 159/751] Moved the clicked-through block check to the top of
the function.
---
src/Blocks/BlockFire.h | 5 ----
src/ClientHandle.cpp | 53 ++++++++++++++----------------------------
2 files changed, 17 insertions(+), 41 deletions(-)
diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h
index f52825362..df50d5962 100644
--- a/src/Blocks/BlockFire.h
+++ b/src/Blocks/BlockFire.h
@@ -40,11 +40,6 @@ public:
FindAndSetPortalFrame(a_BlockX, a_BlockY - 1, a_BlockZ, a_ChunkInterface, a_WorldInterface);
}
- virtual void OnDigging(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
- {
- a_ChunkInterface.DigBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ);
- }
-
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// No pickups from this block
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 8eff45cf4..f09e9531d 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -912,6 +912,23 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
return;
}
+ // Check for clickthrough-blocks:
+ /* When the user breaks a fire block, the client send the wrong block location.
+ We must find the right block with the face direction. */
+ if (a_BlockFace != BLOCK_FACE_NONE)
+ {
+ int BlockX = a_BlockX;
+ int BlockY = a_BlockY;
+ int BlockZ = a_BlockZ;
+ AddFaceDirection(BlockX, BlockY, BlockZ, a_BlockFace);
+ if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(BlockX, BlockY, BlockZ))->IsClickedThrough())
+ {
+ a_BlockX = BlockX;
+ a_BlockY = BlockY;
+ a_BlockZ = BlockZ;
+ }
+ }
+
if (
((a_Status == DIG_STATUS_STARTED) || (a_Status == DIG_STATUS_FINISHED)) && // Only do a radius check for block destruction - things like pickup tossing send coordinates that are to be ignored
((Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) ||
@@ -920,14 +937,6 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
)
{
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- if (a_BlockFace != BLOCK_FACE_NONE)
- {
- AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY, a_BlockZ))->IsClickedThrough())
- {
- m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- }
- }
return;
}
@@ -936,14 +945,6 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
{
// A plugin doesn't agree with the action, replace the block on the client and quit:
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- if (a_BlockFace != BLOCK_FACE_NONE)
- {
- AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY, a_BlockZ))->IsClickedThrough())
- {
- m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- }
- }
return;
}
@@ -1067,26 +1068,6 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
m_LastDigBlockY = a_BlockY;
m_LastDigBlockZ = a_BlockZ;
- // Check for clickthrough-blocks:
- /* When the user breaks a fire block, the client send the wrong block location.
- We must find the right block with the face direction. */
- if (a_BlockFace != BLOCK_FACE_NONE)
- {
- int pX = a_BlockX;
- int pY = a_BlockY;
- int pZ = a_BlockZ;
-
- AddFaceDirection(pX, pY, pZ, a_BlockFace); // Get the block in front of the clicked coordinates (m_bInverse defaulted to false)
- cBlockHandler * Handler = cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(pX, pY, pZ));
-
- if (Handler->IsClickedThrough())
- {
- cChunkInterface ChunkInterface(m_Player->GetWorld()->GetChunkMap());
- Handler->OnDigging(ChunkInterface, *m_Player->GetWorld(), m_Player, pX, pY, pZ);
- return;
- }
- }
-
if (
(m_Player->IsGameModeCreative()) || // In creative mode, digging is done immediately
cBlockInfo::IsOneHitDig(a_OldBlock) // One-hit blocks get destroyed immediately, too
From 01001d2a49a3366e9b1eccf938d5073ab9a2f06e Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 11 Aug 2014 22:37:28 +0200
Subject: [PATCH 160/751] Removes the fire if the block under the fire was
broken.
---
src/ClientHandle.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index f09e9531d..4b5c52c8c 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1143,6 +1143,11 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
World->BroadcastSoundParticleEffect(2001, a_BlockX, a_BlockY, a_BlockZ, a_OldBlock, this);
World->DigBlock(a_BlockX, a_BlockY, a_BlockZ);
+ if (World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) == E_BLOCK_FIRE)
+ {
+ World->SetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0);
+ }
+
cRoot::Get()->GetPluginManager()->CallHookPlayerBrokenBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta);
}
From cb980145820b1bb016dac17a28731cc0b600442a Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 11 Aug 2014 23:12:32 +0200
Subject: [PATCH 161/751] Revert "Removes the fire if the block under the fire
was broken."
This reverts commit 01001d2a49a3366e9b1eccf938d5073ab9a2f06e.
---
src/ClientHandle.cpp | 5 -----
1 file changed, 5 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 4b5c52c8c..f09e9531d 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1143,11 +1143,6 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
World->BroadcastSoundParticleEffect(2001, a_BlockX, a_BlockY, a_BlockZ, a_OldBlock, this);
World->DigBlock(a_BlockX, a_BlockY, a_BlockZ);
- if (World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) == E_BLOCK_FIRE)
- {
- World->SetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, E_BLOCK_AIR, 0);
- }
-
cRoot::Get()->GetPluginManager()->CallHookPlayerBrokenBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta);
}
From 98443682671d0c39b19f86098f7bc900b7529b72 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Tue, 12 Aug 2014 16:05:04 +0100
Subject: [PATCH 162/751] Renamed Loggers
---
Tools/MCADefrag/CMakeLists.txt | 4 +-
Tools/MCADefrag/MCADefrag.cpp | 18 +--
Tools/ProtoProxy/CMakeLists.txt | 4 +-
src/Bindings/ManualBindings.cpp | 10 +-
src/CMakeLists.txt | 7 +-
src/CompositeChat.cpp | 24 ++--
src/CompositeChat.h | 2 +-
src/Globals.h | 2 +-
src/Listeners.cpp | 236 -------------------------------
src/Listeners.h | 21 ---
src/LogDispacher.cpp | 114 ---------------
src/Logger.cpp | 109 ++++++++++++++
src/{LogDispacher.h => Logger.h} | 42 +++---
src/LoggerListeners.cpp | 231 ++++++++++++++++++++++++++++++
src/LoggerListeners.h | 17 +++
src/Root.cpp | 14 +-
src/main.cpp | 2 +-
17 files changed, 418 insertions(+), 439 deletions(-)
delete mode 100644 src/Listeners.cpp
delete mode 100644 src/Listeners.h
delete mode 100644 src/LogDispacher.cpp
create mode 100644 src/Logger.cpp
rename src/{LogDispacher.h => Logger.h} (51%)
create mode 100644 src/LoggerListeners.cpp
create mode 100644 src/LoggerListeners.h
diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt
index e237b6429..42b42018b 100644
--- a/Tools/MCADefrag/CMakeLists.txt
+++ b/Tools/MCADefrag/CMakeLists.txt
@@ -39,8 +39,8 @@ set_exe_flags()
set(SHARED_SRC
../../src/StringCompression.cpp
../../src/StringUtils.cpp
- ../../src/Listeners.cpp
- ../../src/LogDispacher.cpp
+ ../../src/LoggerListeners.cpp
+ ../../src/Logger.cpp
)
set(SHARED_HDR
../../src/ByteBuffer.h
diff --git a/Tools/MCADefrag/MCADefrag.cpp b/Tools/MCADefrag/MCADefrag.cpp
index 702b04ebf..d5d233fd2 100644
--- a/Tools/MCADefrag/MCADefrag.cpp
+++ b/Tools/MCADefrag/MCADefrag.cpp
@@ -5,8 +5,8 @@
#include "Globals.h"
#include "MCADefrag.h"
-#include "LogDispacher.h"
-#include "Listeners.h"
+#include "Logger.h"
+#include "LoggerListeners.h"
#include "zlib/zlib.h"
@@ -22,12 +22,12 @@ static const Byte g_Zeroes[4096] = {0};
int main(int argc, char ** argv)
{
- Logger::cLoggerListener * consoleLogListener = Logger::MakeConsoleListener();
- Logger::cLoggerListener * fileLogListener = new Logger::cFileListener();
- Logger::GetInstance().AttachListener(consoleLogListener);
- Logger::GetInstance().AttachListener(fileLogListener);
+ cLogger::cListener * consoleLogListener = MakeConsoleListener();
+ cLogger::cListener * fileLogListener = new cFileListener();
+ cLogger::GetInstance().AttachListener(consoleLogListener);
+ cLogger::GetInstance().AttachListener(fileLogListener);
- Logger::InitiateMultithreading();
+ cLogger::InitiateMultithreading();
cMCADefrag Defrag;
if (!Defrag.Init(argc, argv))
@@ -37,9 +37,9 @@ int main(int argc, char ** argv)
Defrag.Run();
- Logger::GetInstance().DetachListener(consoleLogListener);
+ cLogger::GetInstance().DetachListener(consoleLogListener);
delete consoleLogListener;
- Logger::GetInstance().DetachListener(fileLogListener);
+ cLogger::GetInstance().DetachListener(fileLogListener);
delete fileLogListener;
return 0;
diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt
index 16c59bb43..bc3923d90 100644
--- a/Tools/ProtoProxy/CMakeLists.txt
+++ b/Tools/ProtoProxy/CMakeLists.txt
@@ -40,8 +40,8 @@ set(SHARED_SRC
../../src/PolarSSL++/CtrDrbgContext.cpp
../../src/PolarSSL++/EntropyContext.cpp
../../src/PolarSSL++/RsaPrivateKey.cpp
- ../../src/Listeners.cpp
- ../../src/LogDispacher.cpp
+ ../../src/LoggerListeners.cpp
+ ../../src/Logger.cpp
)
set(SHARED_HDR
../../src/ByteBuffer.h
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index d792cd0ee..e1e6585f0 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -168,7 +168,7 @@ static AString GetLogMessage(lua_State * tolua_S)
static int tolua_LOG(lua_State * tolua_S)
{
// If the param is a cCompositeChat, read the log level from it:
- Logger::eLogLevel LogLevel = Logger::llRegular;
+ cLogger::eLogLevel LogLevel = cLogger::llRegular;
tolua_Error err;
if (tolua_isusertype(tolua_S, 1, "cCompositeChat", false, &err))
{
@@ -176,7 +176,7 @@ static int tolua_LOG(lua_State * tolua_S)
}
// Log the message:
- Logger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), LogLevel);
+ cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), LogLevel);
return 0;
}
@@ -186,7 +186,7 @@ static int tolua_LOG(lua_State * tolua_S)
static int tolua_LOGINFO(lua_State * tolua_S)
{
- Logger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), Logger::llInfo);
+ cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llInfo);
return 0;
}
@@ -196,7 +196,7 @@ static int tolua_LOGINFO(lua_State * tolua_S)
static int tolua_LOGWARN(lua_State * tolua_S)
{
- Logger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), Logger::llWarning);
+ cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llWarning);
return 0;
}
@@ -206,7 +206,7 @@ static int tolua_LOGWARN(lua_State * tolua_S)
static int tolua_LOGERROR(lua_State * tolua_S)
{
- Logger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), Logger::llError);
+ cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llError);
return 0;
}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bca6a2eb0..8925c9be8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -42,8 +42,8 @@ SET (SRCS
LightingThread.cpp
LineBlockTracer.cpp
LinearInterpolation.cpp
- Listeners.cpp
- LogDispacher.cpp
+ LoggerListeners.cpp
+ Logger.cpp
Map.cpp
MapManager.cpp
MobCensus.cpp
@@ -108,7 +108,8 @@ SET (HDRS
LineBlockTracer.h
LinearInterpolation.h
LinearUpscale.h
- LogDispacher.h
+ Logger.h
+ LoggerListeners.h
Map.h
MapManager.h
Matrix4.h
diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp
index b702447be..0d339021e 100644
--- a/src/CompositeChat.cpp
+++ b/src/CompositeChat.cpp
@@ -353,23 +353,23 @@ AString cCompositeChat::ExtractText(void) const
-Logger::eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageType)
+cLogger::eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageType)
{
switch (a_MessageType)
{
- case mtCustom: return Logger::llRegular;
- case mtFailure: return Logger::llWarning;
- case mtInformation: return Logger::llInfo;
- case mtSuccess: return Logger::llRegular;
- case mtWarning: return Logger::llWarning;
- case mtFatal: return Logger::llError;
- case mtDeath: return Logger::llRegular;
- case mtPrivateMessage: return Logger::llRegular;
- case mtJoin: return Logger::llRegular;
- case mtLeave: return Logger::llRegular;
+ case mtCustom: return cLogger::llRegular;
+ case mtFailure: return cLogger::llWarning;
+ case mtInformation: return cLogger::llInfo;
+ case mtSuccess: return cLogger::llRegular;
+ case mtWarning: return cLogger::llWarning;
+ case mtFatal: return cLogger::llError;
+ case mtDeath: return cLogger::llRegular;
+ case mtPrivateMessage: return cLogger::llRegular;
+ case mtJoin: return cLogger::llRegular;
+ case mtLeave: return cLogger::llRegular;
}
ASSERT(!"Unhandled MessageType");
- return Logger::llError;
+ return cLogger::llError;
}
diff --git a/src/CompositeChat.h b/src/CompositeChat.h
index cc7c446c3..2dc21b98f 100644
--- a/src/CompositeChat.h
+++ b/src/CompositeChat.h
@@ -196,7 +196,7 @@ public:
/** Converts the MessageType to a LogLevel value.
Used by the logging bindings when logging a cCompositeChat object. */
- static Logger::eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType);
+ static cLogger::eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType);
protected:
/** All the parts that */
diff --git a/src/Globals.h b/src/Globals.h
index ae7a68e7f..de1024010 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -249,7 +249,7 @@ template class SizeChecker;
#include "OSSupport/Event.h"
#include "OSSupport/Thread.h"
#include "OSSupport/File.h"
- #include "LogDispacher.h"
+ #include "Logger.h"
#else
// Logging functions
void inline LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);
diff --git a/src/Listeners.cpp b/src/Listeners.cpp
deleted file mode 100644
index 384dcaf91..000000000
--- a/src/Listeners.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-
-#include "Globals.h"
-
-#include "Listeners.h"
-
-#if defined(_WIN32)
- #include // Needed for _isatty(), not available on Linux
-#elif defined(__linux) && !defined(ANDROID_NDK)
- #include // Needed for isatty() on Linux
-#elif defined(ANDROID_NDK)
- #include
-#endif
-
-
-namespace Logger
-{
-
- #if defined(_WIN32) || (defined (__linux) && !defined(ANDROID_NDK))
- class cColouredConsoleListener
- : public cLoggerListener
- {
-
- virtual void SetLogColour(eLogLevel a_LogLevel) = 0;
- virtual void SetDefaultLogColour() = 0;
-
- virtual void Log(AString a_Message, eLogLevel a_LogLevel) override
- {
- SetLogColour(a_LogLevel);
- puts(a_Message.c_str());
- SetDefaultLogColour();
- }
- };
- #endif
-
- #ifdef _WIN32
- class cWindowsConsoleListener
- : public cColouredConsoleListener
- {
- public:
- cWindowsConsoleListener(HANDLE a_Console, WORD a_DefaultConsoleAttrib) :
- m_Console(a_Console),
- m_DefaultConsoleAttrib(a_DefaultConsoleAttrib)
- {
- }
-
- #ifdef DEBUG
- virtual void Log(AString a_Message, eLogLevel a_LogLevel) override
- {
- cColouredConsoleListener::Log(a_Message, a_LogLevel);
- // In a Windows Debug build, output the log to debug console as well:
- OutputDebugStringA(a_Message.c_str());
- }
- #endif // _WIN32
-
-
- virtual void SetLogColour(eLogLevel a_LogLevel) override
- {
- // by default, gray on black
- WORD Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
- switch (a_LogLevel)
- {
- case llRegular:
- // Gray on black
- Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
- break;
- case llInfo:
- // Yellow on black
- Attrib = FOREGROUND_GREEN | ;
- break;
- case llWarning:
- // Red on black
- Attrib = FOREGROUND_RED | FOREGROUND_INTENSITY;
- break;
- case llError:
- // Black on red
- Attrib = BACKGROUND_RED | BACKGROUND_INTENSITY;
- break;
- }
- SetConsoleTextAttribute(m_Console, Attrib);
- }
- virtual void SetDefaultLogColour() override
- {
- SetConsoleTextAttribute(m_Console, m_DefaultConsoleAttrib);
- }
- private:
- HANDLE m_Console;
- WORD m_DefaultConsoleAttrib;
- };
- #elif defined (__linux) && !defined(ANDROID_NDK)
- class cLinuxConsoleListener
- : public cColouredConsoleListener
- {
- public:
- virtual void SetLogColour(eLogLevel a_LogLevel) override
- {
- switch (a_LogLevel)
- {
- case llRegular:
- // Whatever the console default is
- printf("\x1b[0m");
- break;
- case llInfo:
- // Yellow on black
- printf("\x1b[33;1m");
- break;
- case llWarning:
- // Red on black
- printf("\x1b[31;1m");
- break;
- case llError:
- // Yellow on red
- printf("\x1b[1;33;41;1m");
- break;
- }
- }
- virtual void SetDefaultLogColour() override
- {
- // Whatever the console default is
- printf("\x1b[0m");
- }
- };
- #elif defined(ANDROID_NDK)
- class cAndroidConsoleListener
- : public cLoggerListener
- {
- public:
- virtual void Log(AString a_Message, eLogLevel a_LogLevel) override
- {
- android_LogPriority AndroidLogLevel;
- switch (a_LogLevel)
- {
- case llRegular:
- AndroidLogLevel = ANDROID_LOG_VERBOSE;
- break;
- case llInfo:
- AndroidLogLevel = ANDROID_LOG_INFO;
- break;
- case llWarning:
- AndroidLogLevel = ANDROID_LOG_WARNING;
- break;
- case llError:
- AndroidLogLevel = ANDROID_LOG_ERROR;
- break;
- }
- __android_log_print(AndroidLogLevel, "MCServer", "%s", a_Message.c_str());
- }
- };
- #endif
-
- class cVanillaCPPConsoleListener
- : public cLoggerListener
- {
- public:
- virtual void Log(AString a_Message, eLogLevel a_LogLevel) override
- {
- AString LogLevelString;
- switch (a_LogLevel)
- {
- case llRegular:
- LogLevelString = "Log";
- break;
- case llInfo:
- LogLevelString = "Info";
- break;
- case llWarning:
- LogLevelString = "Warning";
- break;
- case llError:
- LogLevelString = "Error";
- break;
- }
- printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
- }
- };
-
-
-
- cLoggerListener * MakeConsoleListener()
- {
- #ifdef _WIN32
- // See whether we are writing to a console the default console attrib:
- bool ShouldColorOutput = (_isatty(_fileno(stdin)) != 0);
- if (ShouldColorOutput)
- {
- CONSOLE_SCREEN_BUFFER_INFO sbi;
- HANDLE Console = getStdHandle(STD_OUTPUT_HANDLE);
- GetConsoleScreenBufferInfo(Console, &sbi);
- WORD DefaultConsoleAttrib = sbi.wAttributes;
- return new cWindowsConsoleListener(Console, DefaultConsoleAttrib);
- } else {
- return new cVanillaCPPConsoleListener();
- }
-
- #elif defined (__linux) && !defined(ANDROID_NDK)
- // TODO: lookup terminal in terminfo
- if (isatty(fileno(stdout)))
- {
- return new cLinuxConsoleListener();
- } else {
- return new cVanillaCPPConsoleListener();
- }
- #else
- return new cVanillaCPPConsoleListener();
- #endif
- }
-
- cFileListener::cFileListener()
- {
- cFile::CreateFolder(FILE_IO_PREFIX + AString("logs"));
- AString FileName;
- FileName = Printf("%s%sLOG_%d.txt", FILE_IO_PREFIX, "logs/", (int)time(NULL));
- m_File.Open(FileName, cFile::fmAppend);
- }
-
- void cFileListener::Log(AString a_Message, eLogLevel a_LogLevel)
- {
- AString LogLevelString;
- switch (a_LogLevel)
- {
- case llRegular:
- LogLevelString = "Log";
- break;
- case llInfo:
- LogLevelString = "Info";
- break;
- case llWarning:
- LogLevelString = "Warning";
- break;
- case llError:
- LogLevelString = "Error";
- break;
- }
- m_File.Printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
- }
-
-}
diff --git a/src/Listeners.h b/src/Listeners.h
deleted file mode 100644
index bc29d0c06..000000000
--- a/src/Listeners.h
+++ /dev/null
@@ -1,21 +0,0 @@
-
-#include "LogDispacher.h"
-
-namespace Logger
-{
-
- class cFileListener
- : public cLoggerListener
- {
- public:
-
- cFileListener();
- cFileListener(AString a_Filename);
-
- virtual void Log(AString a_Message, eLogLevel a_LogLevel) override;
- private:
- cFile m_File;
- };
-
- cLoggerListener * MakeConsoleListener();
-}
diff --git a/src/LogDispacher.cpp b/src/LogDispacher.cpp
deleted file mode 100644
index abca6a898..000000000
--- a/src/LogDispacher.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "OSSupport/IsThread.h"
-
-
-
-namespace Logger
-{
-
- cLogDispacher & GetInstance(void)
- {
- static cLogDispacher Instance;
- return Instance;
- }
-
- void InitiateMultithreading()
- {
- GetInstance();
- }
-
- void cLogDispacher::LogSimple(AString a_Message, eLogLevel a_LogLevel)
- {
- time_t rawtime;
- time ( &rawtime);
-
- struct tm* timeinfo;
- #ifdef _MSC_VER
- struct tm timeinforeal;
- timeinfo = &timeinforeal;
- localtime_s(timeinfo, &rawtime);
- #else
- timeinfo = localtime( &rawtime);
- #endif
-
- AString Line;
- #ifdef _DEBUG
- Printf(Line, "[%04lx|%02d:%02d:%02d] %s\n", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
- #else
- Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
- #endif
-
-
- cCSLock Lock(m_CriticalSection);
- for(size_t i = 0; i < m_LogListeners.size(); i++)
- {
- m_LogListeners[i]->Log(a_Message, a_LogLevel);
- }
- }
-
-
-
-
-
- void cLogDispacher::Log(const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList)
- {
- AString Message;
- AppendVPrintf(Message, a_Format, a_ArgList);
- LogSimple(Message, a_LogLevel);
- }
-
- void cLogDispacher::AttachListener(Logger::cLoggerListener * a_Listener)
- {
- cCSLock Lock(m_CriticalSection);
- m_LogListeners.push_back(a_Listener);
- }
-
- void cLogDispacher::DetachListener(Logger::cLoggerListener * a_Listener)
- {
- cCSLock Lock(m_CriticalSection);
- m_LogListeners.erase(std::remove(m_LogListeners.begin(), m_LogListeners.end(), a_Listener));
- }
-};
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// Global functions
-
-void LOG(const char* a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- Logger::GetInstance().Log(a_Format, Logger::llRegular, argList);
- va_end(argList);
-}
-
-void LOGINFO(const char* a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- Logger::GetInstance().Log( a_Format, Logger::llInfo, argList);
- va_end(argList);
-}
-
-void LOGWARN(const char* a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- Logger::GetInstance().Log( a_Format, Logger::llWarning, argList);
- va_end(argList);
-}
-
-void LOGERROR(const char* a_Format, ...)
-{
- va_list argList;
- va_start(argList, a_Format);
- Logger::GetInstance().Log( a_Format, Logger::llError, argList);
- va_end(argList);
-}
-
-
-
-
diff --git a/src/Logger.cpp b/src/Logger.cpp
new file mode 100644
index 000000000..e0ea973f8
--- /dev/null
+++ b/src/Logger.cpp
@@ -0,0 +1,109 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "OSSupport/IsThread.h"
+
+
+cLogger & cLogger::GetInstance(void)
+{
+ static cLogger Instance;
+ return Instance;
+}
+
+void cLogger::InitiateMultithreading()
+{
+ GetInstance();
+}
+
+void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
+{
+ time_t rawtime;
+ time ( &rawtime);
+
+ struct tm* timeinfo;
+ #ifdef _MSC_VER
+ struct tm timeinforeal;
+ timeinfo = &timeinforeal;
+ localtime_s(timeinfo, &rawtime);
+ #else
+ timeinfo = localtime( &rawtime);
+ #endif
+
+ AString Line;
+ #ifdef _DEBUG
+ Printf(Line, "[%04lx|%02d:%02d:%02d] %s\n", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ #else
+ Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ #endif
+
+
+ cCSLock Lock(m_CriticalSection);
+ for(size_t i = 0; i < m_LogListeners.size(); i++)
+ {
+ m_LogListeners[i]->Log(a_Message, a_LogLevel);
+ }
+}
+
+
+
+
+
+void cLogger::Log(const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList)
+{
+ AString Message;
+ AppendVPrintf(Message, a_Format, a_ArgList);
+ LogSimple(Message, a_LogLevel);
+}
+
+void cLogger::AttachListener(cListener * a_Listener)
+{
+ cCSLock Lock(m_CriticalSection);
+ m_LogListeners.push_back(a_Listener);
+}
+
+void cLogger::DetachListener(cListener * a_Listener)
+{
+ cCSLock Lock(m_CriticalSection);
+ m_LogListeners.erase(std::remove(m_LogListeners.begin(), m_LogListeners.end(), a_Listener));
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Global functions
+
+void LOG(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cLogger::GetInstance().Log(a_Format, cLogger::llRegular, argList);
+ va_end(argList);
+}
+
+void LOGINFO(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cLogger::GetInstance().Log( a_Format, cLogger::llInfo, argList);
+ va_end(argList);
+}
+
+void LOGWARN(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cLogger::GetInstance().Log( a_Format, cLogger::llWarning, argList);
+ va_end(argList);
+}
+
+void LOGERROR(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cLogger::GetInstance().Log( a_Format, cLogger::llError, argList);
+ va_end(argList);
+}
+
+
+
+
diff --git a/src/LogDispacher.h b/src/Logger.h
similarity index 51%
rename from src/LogDispacher.h
rename to src/Logger.h
index 1472b392a..5e65de8a8 100644
--- a/src/LogDispacher.h
+++ b/src/Logger.h
@@ -2,8 +2,9 @@
#pragma once
-namespace Logger
+class cLogger
{
+public:
enum eLogLevel
{
@@ -13,41 +14,32 @@ namespace Logger
llError,
};
- class cLogDispacher;
- // Must be called before calling GetInstance in a multithreaded context
- void InitiateMultithreading();
-
- cLogDispacher & GetInstance(void);
-
- class cLoggerListener
+ class cListener
{
public:
virtual void Log(AString a_Message, eLogLevel a_LogLevel) = 0;
-
- virtual ~cLoggerListener(){}
+
+ virtual ~cListener(){}
};
- class cLogDispacher
- {
- public:
+ void Log (const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList) FORMATSTRING(2, 0);
- void Log (const char * a_Format, Logger::eLogLevel a_LogLevel, va_list a_ArgList) FORMATSTRING(2, 0);
+ /** Logs the simple text message at the specified log level. */
+ void LogSimple(AString a_Message, eLogLevel a_LogLevel = llRegular);
- /** Logs the simple text message at the specified log level. */
- void LogSimple(AString a_Message, Logger::eLogLevel a_LogLevel = Logger::llRegular);
+ void AttachListener(cListener * a_Listener);
+ void DetachListener(cListener * a_Listener);
- void AttachListener(Logger::cLoggerListener * a_Listener);
- void DetachListener(Logger::cLoggerListener * a_Listener);
+ static cLogger & GetInstance(void);
+ // Must be called before calling GetInstance in a multithreaded context
+ static void InitiateMultithreading();
+private:
- private:
-
- cCriticalSection m_CriticalSection;
- std::vector m_LogListeners;
-
- };
+ cCriticalSection m_CriticalSection;
+ std::vector m_LogListeners;
-}
+};
diff --git a/src/LoggerListeners.cpp b/src/LoggerListeners.cpp
new file mode 100644
index 000000000..d6567abe0
--- /dev/null
+++ b/src/LoggerListeners.cpp
@@ -0,0 +1,231 @@
+
+#include "Globals.h"
+
+#include "LoggerListeners.h"
+
+#if defined(_WIN32)
+ #include // Needed for _isatty(), not available on Linux
+#elif defined(__linux) && !defined(ANDROID_NDK)
+ #include // Needed for isatty() on Linux
+#elif defined(ANDROID_NDK)
+ #include
+#endif
+
+
+#if defined(_WIN32) || (defined (__linux) && !defined(ANDROID_NDK))
+ class cColouredConsoleListener
+ : public cLogger::cListener
+ {
+
+ virtual void SetLogColour(cLogger::eLogLevel a_LogLevel) = 0;
+ virtual void SetDefaultLogColour() = 0;
+
+ virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override
+ {
+ SetLogColour(a_LogLevel);
+ puts(a_Message.c_str());
+ SetDefaultLogColour();
+ }
+ };
+#endif
+
+#ifdef _WIN32
+ class cWindowsConsoleListener
+ : public cColouredConsoleListener
+ {
+ public:
+ cWindowsConsoleListener(HANDLE a_Console, WORD a_DefaultConsoleAttrib) :
+ m_Console(a_Console),
+ m_DefaultConsoleAttrib(a_DefaultConsoleAttrib)
+ {
+ }
+
+ #ifdef DEBUG
+ virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override
+ {
+ cColouredConsoleListener::Log(a_Message, a_LogLevel);
+ // In a Windows Debug build, output the log to debug console as well:
+ OutputDebugStringA(a_Message.c_str());
+ }
+ #endif
+
+
+ virtual void SetLogColour(cLogger::eLogLevel a_LogLevel) override
+ {
+ // by default, gray on black
+ WORD Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
+ switch (a_LogLevel)
+ {
+ case cLogger::llRegular:
+ // Gray on black
+ Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
+ break;
+ case cLogger::llInfo:
+ // Yellow on black
+ Attrib = FOREGROUND_GREEN | ;
+ break;
+ case cLogger::llWarning:
+ // Red on black
+ Attrib = FOREGROUND_RED | FOREGROUND_INTENSITY;
+ break;
+ case cLogger::llError:
+ // Black on red
+ Attrib = BACKGROUND_RED | BACKGROUND_INTENSITY;
+ break;
+ }
+ SetConsoleTextAttribute(m_Console, Attrib);
+ }
+ virtual void SetDefaultLogColour() override
+ {
+ SetConsoleTextAttribute(m_Console, m_DefaultConsoleAttrib);
+ }
+ private:
+ HANDLE m_Console;
+ WORD m_DefaultConsoleAttrib;
+ };
+#elif defined (__linux) && !defined(ANDROID_NDK)
+ class cLinuxConsoleListener
+ : public cColouredConsoleListener
+ {
+ public:
+ virtual void SetLogColour(cLogger::eLogLevel a_LogLevel) override
+ {
+ switch (a_LogLevel)
+ {
+ case cLogger::llRegular:
+ // Whatever the console default is
+ printf("\x1b[0m");
+ break;
+ case cLogger::llInfo:
+ // Yellow on black
+ printf("\x1b[33;1m");
+ break;
+ case cLogger::llWarning:
+ // Red on black
+ printf("\x1b[31;1m");
+ break;
+ case cLogger::llError:
+ // Yellow on red
+ printf("\x1b[1;33;41;1m");
+ break;
+ }
+ }
+ virtual void SetDefaultLogColour() override
+ {
+ // Whatever the console default is
+ printf("\x1b[0m");
+ }
+ };
+#elif defined(ANDROID_NDK)
+ class cAndroidConsoleListener
+ : public cLogger::cListener
+ {
+ public:
+ virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override
+ {
+ android_LogPriority AndroidLogLevel;
+ switch (a_LogLevel)
+ {
+ case cLogger::llRegular:
+ AndroidLogLevel = ANDROID_LOG_VERBOSE;
+ break;
+ case cLogger::llInfo:
+ AndroidLogLevel = ANDROID_LOG_INFO;
+ break;
+ case cLogger::llWarning:
+ AndroidLogLevel = ANDROID_LOG_WARNING;
+ break;
+ case cLogger::llError:
+ AndroidLogLevel = ANDROID_LOG_ERROR;
+ break;
+ }
+ __android_log_print(AndroidLogLevel, "MCServer", "%s", a_Message.c_str());
+ }
+ };
+#endif
+
+class cVanillaCPPConsoleListener
+ : public cLogger::cListener
+{
+public:
+ virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override
+ {
+ AString LogLevelString;
+ switch (a_LogLevel)
+ {
+ case cLogger::llRegular:
+ LogLevelString = "Log";
+ break;
+ case cLogger::llInfo:
+ LogLevelString = "Info";
+ break;
+ case cLogger::llWarning:
+ LogLevelString = "Warning";
+ break;
+ case cLogger::llError:
+ LogLevelString = "Error";
+ break;
+ }
+ printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
+ }
+};
+
+
+
+cLogger::cListener * MakeConsoleListener()
+{
+ #ifdef _WIN32
+ // See whether we are writing to a console the default console attrib:
+ bool ShouldColorOutput = (_isatty(_fileno(stdin)) != 0);
+ if (ShouldColorOutput)
+ {
+ CONSOLE_SCREEN_BUFFER_INFO sbi;
+ HANDLE Console = getStdHandle(STD_OUTPUT_HANDLE);
+ GetConsoleScreenBufferInfo(Console, &sbi);
+ WORD DefaultConsoleAttrib = sbi.wAttributes;
+ return new cWindowsConsoleListener(Console, DefaultConsoleAttrib);
+ } else {
+ return new cVanillaCPPConsoleListener();
+ }
+
+ #elif defined (__linux) && !defined(ANDROID_NDK)
+ // TODO: lookup terminal in terminfo
+ if (isatty(fileno(stdout)))
+ {
+ return new cLinuxConsoleListener();
+ } else {
+ return new cVanillaCPPConsoleListener();
+ }
+ #else
+ return new cVanillaCPPConsoleListener();
+ #endif
+}
+
+cFileListener::cFileListener()
+{
+ cFile::CreateFolder(FILE_IO_PREFIX + AString("logs"));
+ AString FileName;
+ FileName = Printf("%s%sLOG_%d.txt", FILE_IO_PREFIX, "logs/", (int)time(NULL));
+ m_File.Open(FileName, cFile::fmAppend);
+}
+
+void cFileListener::Log(AString a_Message, cLogger::eLogLevel a_LogLevel)
+{
+ AString LogLevelString;
+ switch (a_LogLevel)
+ {
+ case cLogger::llRegular:
+ LogLevelString = "Log";
+ break;
+ case cLogger::llInfo:
+ LogLevelString = "Info";
+ break;
+ case cLogger::llWarning:
+ LogLevelString = "Warning";
+ break;
+ case cLogger::llError:
+ LogLevelString = "Error";
+ break;
+ }
+ m_File.Printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
+}
diff --git a/src/LoggerListeners.h b/src/LoggerListeners.h
new file mode 100644
index 000000000..4d2889a93
--- /dev/null
+++ b/src/LoggerListeners.h
@@ -0,0 +1,17 @@
+
+#include "Logger.h"
+
+class cFileListener
+ : public cLogger::cListener
+{
+ public:
+
+ cFileListener();
+ cFileListener(AString a_Filename);
+
+ virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override;
+ private:
+ cFile m_File;
+};
+
+cLogger::cListener * MakeConsoleListener();
diff --git a/src/Root.cpp b/src/Root.cpp
index 72048b631..ee0d9b835 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -18,7 +18,7 @@
#include "CommandOutput.h"
#include "DeadlockDetect.h"
#include "OSSupport/Timer.h"
-#include "Listeners.h"
+#include "LoggerListeners.h"
#include "inifile/iniFile.h"
@@ -106,10 +106,10 @@ void cRoot::Start(void)
EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); // Disable close button when starting up; it causes problems with our CTRL-CLOSE handling
#endif
- Logger::cLoggerListener * consoleLogListener = Logger::MakeConsoleListener();
- Logger::cLoggerListener * fileLogListener = new Logger::cFileListener();
- Logger::GetInstance().AttachListener(consoleLogListener);
- Logger::GetInstance().AttachListener(fileLogListener);
+ cLogger::cListener * consoleLogListener = MakeConsoleListener();
+ cLogger::cListener * fileLogListener = new cFileListener();
+ cLogger::GetInstance().AttachListener(consoleLogListener);
+ cLogger::GetInstance().AttachListener(fileLogListener);
LOG("--- Started Log ---\n");
@@ -257,9 +257,9 @@ void cRoot::Start(void)
LOG("--- Stopped Log ---");
- Logger::GetInstance().DetachListener(consoleLogListener);
+ cLogger::GetInstance().DetachListener(consoleLogListener);
delete consoleLogListener;
- Logger::GetInstance().DetachListener(fileLogListener);
+ cLogger::GetInstance().DetachListener(fileLogListener);
delete fileLogListener;
}
diff --git a/src/main.cpp b/src/main.cpp
index e40035538..86ecd4000 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -273,7 +273,7 @@ int main( int argc, char **argv)
}
} // for i - argv[]
- Logger::InitiateMultithreading();
+ cLogger::InitiateMultithreading();
#if !defined(ANDROID_NDK)
try
From 01c50eb53ab06f99fd08a2d599095e6dec683b60 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Tue, 12 Aug 2014 17:32:08 +0100
Subject: [PATCH 163/751] Fix messing rename
---
src/Bindings/LuaFunctions.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Bindings/LuaFunctions.h b/src/Bindings/LuaFunctions.h
index 6a645ed53..be1d9aaa9 100644
--- a/src/Bindings/LuaFunctions.h
+++ b/src/Bindings/LuaFunctions.h
@@ -1,6 +1,6 @@
#pragma once
-#include "LogDispacher.h"
+#include "Logger.h"
#include
// tolua_begin
From 10e58f04da038a28626fee90d278c703d55f72b6 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 12 Aug 2014 22:43:04 +0200
Subject: [PATCH 164/751] Fixed windows compilation and style issues.
---
src/Logger.cpp | 56 ++++++++++++++----
src/LoggerListeners.cpp | 122 ++++++++++++++++++++++++++++++++++------
src/LoggerListeners.h | 28 ++++++---
src/OSSupport/File.h | 8 +--
4 files changed, 177 insertions(+), 37 deletions(-)
diff --git a/src/Logger.cpp b/src/Logger.cpp
index e0ea973f8..572a0e160 100644
--- a/src/Logger.cpp
+++ b/src/Logger.cpp
@@ -2,6 +2,12 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "OSSupport/IsThread.h"
+#ifdef _WIN32
+ #include
+#endif
+
+
+
cLogger & cLogger::GetInstance(void)
@@ -10,35 +16,43 @@ cLogger & cLogger::GetInstance(void)
return Instance;
}
+
+
+
+
void cLogger::InitiateMultithreading()
{
GetInstance();
}
+
+
+
+
void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
{
time_t rawtime;
- time ( &rawtime);
+ time(&rawtime);
- struct tm* timeinfo;
+ struct tm * timeinfo;
#ifdef _MSC_VER
struct tm timeinforeal;
timeinfo = &timeinforeal;
localtime_s(timeinfo, &rawtime);
#else
- timeinfo = localtime( &rawtime);
+ timeinfo = localtime(&rawtime);
#endif
AString Line;
#ifdef _DEBUG
- Printf(Line, "[%04lx|%02d:%02d:%02d] %s\n", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ Printf(Line, "[%04lx|%02d:%02d:%02d] %s\n", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
#else
- Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
#endif
cCSLock Lock(m_CriticalSection);
- for(size_t i = 0; i < m_LogListeners.size(); i++)
+ for (size_t i = 0; i < m_LogListeners.size(); i++)
{
m_LogListeners[i]->Log(a_Message, a_LogLevel);
}
@@ -55,12 +69,20 @@ void cLogger::Log(const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList
LogSimple(Message, a_LogLevel);
}
+
+
+
+
void cLogger::AttachListener(cListener * a_Listener)
{
cCSLock Lock(m_CriticalSection);
m_LogListeners.push_back(a_Listener);
}
+
+
+
+
void cLogger::DetachListener(cListener * a_Listener)
{
cCSLock Lock(m_CriticalSection);
@@ -69,10 +91,12 @@ void cLogger::DetachListener(cListener * a_Listener)
+
+
////////////////////////////////////////////////////////////////////////////////
// Global functions
-void LOG(const char* a_Format, ...)
+void LOG(const char * a_Format, ...)
{
va_list argList;
va_start(argList, a_Format);
@@ -80,7 +104,11 @@ void LOG(const char* a_Format, ...)
va_end(argList);
}
-void LOGINFO(const char* a_Format, ...)
+
+
+
+
+void LOGINFO(const char * a_Format, ...)
{
va_list argList;
va_start(argList, a_Format);
@@ -88,7 +116,11 @@ void LOGINFO(const char* a_Format, ...)
va_end(argList);
}
-void LOGWARN(const char* a_Format, ...)
+
+
+
+
+void LOGWARN(const char * a_Format, ...)
{
va_list argList;
va_start(argList, a_Format);
@@ -96,7 +128,11 @@ void LOGWARN(const char* a_Format, ...)
va_end(argList);
}
-void LOGERROR(const char* a_Format, ...)
+
+
+
+
+void LOGERROR(const char * a_Format, ...)
{
va_list argList;
va_start(argList, a_Format);
diff --git a/src/LoggerListeners.cpp b/src/LoggerListeners.cpp
index d6567abe0..912342a65 100644
--- a/src/LoggerListeners.cpp
+++ b/src/LoggerListeners.cpp
@@ -5,6 +5,7 @@
#if defined(_WIN32)
#include // Needed for _isatty(), not available on Linux
+ #include
#elif defined(__linux) && !defined(ANDROID_NDK)
#include // Needed for isatty() on Linux
#elif defined(ANDROID_NDK)
@@ -29,10 +30,15 @@
};
#endif
+
+
+
+
#ifdef _WIN32
class cWindowsConsoleListener
: public cColouredConsoleListener
{
+ typedef cColouredConsoleListener super;
public:
cWindowsConsoleListener(HANDLE a_Console, WORD a_DefaultConsoleAttrib) :
m_Console(a_Console),
@@ -43,47 +49,65 @@
#ifdef DEBUG
virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override
{
- cColouredConsoleListener::Log(a_Message, a_LogLevel);
+ super::Log(a_Message, a_LogLevel);
// In a Windows Debug build, output the log to debug console as well:
OutputDebugStringA(a_Message.c_str());
}
#endif
-
-
+
+
virtual void SetLogColour(cLogger::eLogLevel a_LogLevel) override
{
// by default, gray on black
- WORD Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
+ WORD Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
switch (a_LogLevel)
{
case cLogger::llRegular:
+ {
// Gray on black
- Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
- break;
+ Attrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
+ break;
+ }
case cLogger::llInfo:
+ {
// Yellow on black
- Attrib = FOREGROUND_GREEN | ;
- break;
+ Attrib = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;
+ break;
+ }
case cLogger::llWarning:
+ {
// Red on black
Attrib = FOREGROUND_RED | FOREGROUND_INTENSITY;
- break;
+ break;
+ }
case cLogger::llError:
- // Black on red
+ {
+ // Black on red
Attrib = BACKGROUND_RED | BACKGROUND_INTENSITY;
break;
+ }
}
SetConsoleTextAttribute(m_Console, Attrib);
}
+
+
virtual void SetDefaultLogColour() override
{
SetConsoleTextAttribute(m_Console, m_DefaultConsoleAttrib);
}
+
private:
+
HANDLE m_Console;
WORD m_DefaultConsoleAttrib;
};
+
+
+
#elif defined (__linux) && !defined(ANDROID_NDK)
+
+
+
class cLinuxConsoleListener
: public cColouredConsoleListener
{
@@ -93,30 +117,46 @@
switch (a_LogLevel)
{
case cLogger::llRegular:
+ {
// Whatever the console default is
printf("\x1b[0m");
break;
+ }
case cLogger::llInfo:
+ {
// Yellow on black
printf("\x1b[33;1m");
break;
+ }
case cLogger::llWarning:
+ {
// Red on black
printf("\x1b[31;1m");
break;
+ }
case cLogger::llError:
+ {
// Yellow on red
printf("\x1b[1;33;41;1m");
break;
+ }
}
}
+
+
virtual void SetDefaultLogColour() override
{
// Whatever the console default is
printf("\x1b[0m");
}
};
+
+
+
#elif defined(ANDROID_NDK)
+
+
+
class cAndroidConsoleListener
: public cLogger::cListener
{
@@ -127,23 +167,36 @@
switch (a_LogLevel)
{
case cLogger::llRegular:
+ {
AndroidLogLevel = ANDROID_LOG_VERBOSE;
break;
+ }
case cLogger::llInfo:
+ {
AndroidLogLevel = ANDROID_LOG_INFO;
break;
+ }
case cLogger::llWarning:
+ {
AndroidLogLevel = ANDROID_LOG_WARNING;
break;
+ }
case cLogger::llError:
+ {
AndroidLogLevel = ANDROID_LOG_ERROR;
break;
+ }
}
__android_log_print(AndroidLogLevel, "MCServer", "%s", a_Message.c_str());
}
};
+
#endif
+
+
+
+
class cVanillaCPPConsoleListener
: public cLogger::cListener
{
@@ -154,17 +207,25 @@ public:
switch (a_LogLevel)
{
case cLogger::llRegular:
+ {
LogLevelString = "Log";
break;
+ }
case cLogger::llInfo:
+ {
LogLevelString = "Info";
break;
+ }
case cLogger::llWarning:
+ {
LogLevelString = "Warning";
break;
+ }
case cLogger::llError:
+ {
LogLevelString = "Error";
break;
+ }
}
printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
}
@@ -172,7 +233,9 @@ public:
-cLogger::cListener * MakeConsoleListener()
+
+
+cLogger::cListener * MakeConsoleListener(void)
{
#ifdef _WIN32
// See whether we are writing to a console the default console attrib:
@@ -180,12 +243,14 @@ cLogger::cListener * MakeConsoleListener()
if (ShouldColorOutput)
{
CONSOLE_SCREEN_BUFFER_INFO sbi;
- HANDLE Console = getStdHandle(STD_OUTPUT_HANDLE);
+ HANDLE Console = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(Console, &sbi);
WORD DefaultConsoleAttrib = sbi.wAttributes;
return new cWindowsConsoleListener(Console, DefaultConsoleAttrib);
- } else {
- return new cVanillaCPPConsoleListener();
+ }
+ else
+ {
+ return new cVanillaCPPConsoleListener;
}
#elif defined (__linux) && !defined(ANDROID_NDK)
@@ -193,7 +258,9 @@ cLogger::cListener * MakeConsoleListener()
if (isatty(fileno(stdout)))
{
return new cLinuxConsoleListener();
- } else {
+ }
+ else
+ {
return new cVanillaCPPConsoleListener();
}
#else
@@ -201,7 +268,14 @@ cLogger::cListener * MakeConsoleListener()
#endif
}
-cFileListener::cFileListener()
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// cFileListener:
+
+cFileListener::cFileListener(void)
{
cFile::CreateFolder(FILE_IO_PREFIX + AString("logs"));
AString FileName;
@@ -209,23 +283,39 @@ cFileListener::cFileListener()
m_File.Open(FileName, cFile::fmAppend);
}
+
+
+
+
void cFileListener::Log(AString a_Message, cLogger::eLogLevel a_LogLevel)
{
AString LogLevelString;
switch (a_LogLevel)
{
case cLogger::llRegular:
+ {
LogLevelString = "Log";
break;
+ }
case cLogger::llInfo:
+ {
LogLevelString = "Info";
break;
+ }
case cLogger::llWarning:
+ {
LogLevelString = "Warning";
break;
+ }
case cLogger::llError:
+ {
LogLevelString = "Error";
break;
+ }
}
m_File.Printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
}
+
+
+
+
diff --git a/src/LoggerListeners.h b/src/LoggerListeners.h
index 4d2889a93..d300184b1 100644
--- a/src/LoggerListeners.h
+++ b/src/LoggerListeners.h
@@ -1,17 +1,31 @@
#include "Logger.h"
+
+
+
+
class cFileListener
: public cLogger::cListener
{
- public:
+public:
+
+ cFileListener();
+ cFileListener(AString a_Filename);
+
+ virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override;
- cFileListener();
- cFileListener(AString a_Filename);
-
- virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override;
- private:
- cFile m_File;
+private:
+
+ cFile m_File;
};
+
+
+
+
cLogger::cListener * MakeConsoleListener();
+
+
+
+
diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h
index 8891511c4..dfb38e839 100644
--- a/src/OSSupport/File.h
+++ b/src/OSSupport/File.h
@@ -60,10 +60,10 @@ public:
/** The mode in which to open the file */
enum eMode
{
- fmRead, // Read-only. If the file doesn't exist, object will not be valid
- fmWrite, // Write-only. If the file already exists, it will be overwritten
- fmReadWrite, // Read/write. If the file already exists, it will be left intact; writing will overwrite the data from the beginning
- fmAppend // Write-only. If the file already exists cursor will be moved to the end of the file
+ fmRead, // Read-only. If the file doesn't exist, object will not be valid
+ fmWrite, // Write-only. If the file already exists, it will be overwritten
+ fmReadWrite, // Read/write. If the file already exists, it will be left intact; writing will overwrite the data from the beginning
+ fmAppend // Write-only. If the file already exists cursor will be moved to the end of the file
} ;
/** Simple constructor - creates an unopened file object, use Open() to open / create a real file */
From e110f7226895b1629f72a52c7953d8f00a1f63c6 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 13 Aug 2014 09:53:33 +0200
Subject: [PATCH 165/751] RankMgr: Initial migration code.
---
src/RankManager.cpp | 542 +++++++++++++++++++++++++++++++++++++++++++-
src/RankManager.h | 28 +++
src/Root.cpp | 1 +
3 files changed, 569 insertions(+), 2 deletions(-)
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index 3627afadb..9809f1d6c 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -6,6 +6,8 @@
#include "Globals.h"
#include "RankManager.h"
#include "SQLiteCpp/Transaction.h"
+#include "inifile/iniFile.h"
+#include "Protocol/MojangAPI.h"
@@ -219,9 +221,367 @@ protected:
-cRankManager::cRankManager(void) :
- m_DB("Ranks.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)
+////////////////////////////////////////////////////////////////////////////////
+/** Migrates from groups.ini and users.ini into the rankmanager DB */
+class cRankManagerIniMigrator
{
+public:
+ cRankManagerIniMigrator(cRankManager & a_RankManager, cMojangAPI & a_MojangAPI) :
+ m_RankManager(a_RankManager),
+ m_MojangAPI(a_MojangAPI)
+ {
+ }
+
+
+
+ /** Performs the complete migration from INI files to DB. */
+ bool Migrate(void)
+ {
+ LOGD("Reading groups...");
+ if (!ReadGroups())
+ {
+ return false;
+ }
+ LOGD("Cleaning groups inheritance...");
+ CleanGroupInheritance();
+ LOGD("Creating groups...");
+ CreateGroups();
+
+ LOGD("Reading users...");
+ if (!ReadUsers())
+ {
+ return false;
+ }
+ LOGD("Cleaning user groups...");
+ CleanUserGroups();
+ LOGD("Resolving user UUIDs...");
+ ResolveUserUUIDs();
+
+ LOGD("Setting ranks...");
+ SetRanks();
+
+ return true;
+ }
+
+protected:
+
+ /** Container for a group read from an INI file. */
+ struct sGroup
+ {
+ AString m_Name;
+ AString m_Color;
+ AStringVector m_Inherits;
+ AStringVector m_Permissions;
+
+ sGroup(void) {}
+
+ sGroup(const AString & a_Name, const AString & a_Color, const AStringVector & a_Inherits, const AStringVector & a_Permissions):
+ m_Name(a_Name),
+ m_Color(a_Color),
+ m_Inherits(a_Inherits),
+ m_Permissions(a_Permissions)
+ {
+ }
+ };
+ typedef std::map sGroupMap;
+
+
+ /** Container for a single user read from an INI file. */
+ struct sUser
+ {
+ AString m_Name;
+ AStringVector m_Groups;
+
+ /** Assigned by ResolveUserUUIDs() */
+ AString m_UUID;
+
+
+ sUser(void) {}
+
+ sUser(const AString & a_Name, const AStringVector & a_Groups):
+ m_Name(a_Name),
+ m_Groups(a_Groups)
+ {
+ }
+ };
+ typedef std::map sUserMap;
+
+ typedef std::map cStringMap;
+
+
+ /** The parent Rank manager where we will create the groups, ranks and players */
+ cRankManager & m_RankManager;
+
+ /** The player name to UUID resolver */
+ cMojangAPI & m_MojangAPI;
+
+ /** List of all groups read from the ini file */
+ sGroupMap m_Groups;
+
+ /** List of all players read from the ini file. */
+ sUserMap m_Users;
+
+ /** Maps lists of groups to rank names.
+ Each group list is either a simple "" if there's only one group,
+ or ",,...", where the secondary groups are
+ lowercased and alpha-sorted. This makes the group lists comparable for equivalence, simply by comparing
+ their string names.
+ The ranks are named "" for single-group players, and "AutoMigratedRank_N" for the composite ranks,
+ where N is a unique number. */
+ cStringMap m_GroupsToRanks;
+
+
+
+ /** Reads the groups from the "groups.ini" file into m_Groups */
+ bool ReadGroups(void)
+ {
+ // Read the file:
+ cIniFile Groups;
+ if (!Groups.ReadFile("groups.ini"))
+ {
+ return false;
+ }
+
+ // Read all the groups into a map:
+ int NumGroups = Groups.GetNumKeys();
+ for (int i = 0; i < NumGroups; i++)
+ {
+ AString GroupName = Groups.GetKeyName(i);
+ AString lcGroupName = StrToLower(GroupName);
+ if (m_Groups.find(lcGroupName) != m_Groups.end())
+ {
+ LOGINFO("groups.ini contains a duplicate definition of group %s, ignoring the latter.", GroupName.c_str());
+ continue;
+ }
+ m_Groups[lcGroupName] = sGroup(
+ GroupName,
+ Groups.GetValue(GroupName, "Color", ""),
+ StringSplitAndTrim(Groups.GetValue(GroupName, "Inherits"), ","),
+ StringSplitAndTrim(Groups.GetValue(GroupName, "Permissions"), ",")
+ );
+ } // for i - Groups' keys
+ return true;
+ }
+
+
+
+ /** Removes non-existent groups from all the groups' inheritance */
+ void CleanGroupInheritance(void)
+ {
+ for (sGroupMap::iterator itrG = m_Groups.begin(), endG = m_Groups.end(); itrG != endG; ++itrG)
+ {
+ AStringVector & Inherits = itrG->second.m_Inherits;
+ for (AStringVector::iterator itrI = Inherits.begin(); itrI != Inherits.end();)
+ {
+ AString lcInherits = StrToLower(*itrI);
+ if (m_Groups.find(lcInherits) != m_Groups.end())
+ {
+ // Inherited group exists, continue checking the next one
+ ++itrI;
+ continue;
+ }
+ // Inherited group doesn't exist, remove it from the list:
+ LOGWARNING("RankMigrator: Group \"%s\" inherits from a non-existent group \"%s\", this inheritance will be ignored.",
+ itrG->second.m_Name.c_str(), itrI->c_str()
+ );
+ AStringVector::iterator itrI2 = itrI;
+ ++itrI2;
+ Inherits.erase(itrI);
+ itrI = itrI2;
+ } // for itrI - Inherits[]
+ } // for itrG - m_Groups[]
+ }
+
+
+
+ /** Reads the users from the "users.ini" file into m_Users */
+ bool ReadUsers(void)
+ {
+ // Read the file:
+ cIniFile Users;
+ if (!Users.ReadFile("users.ini"))
+ {
+ return false;
+ }
+
+ // Read all the users into a map:
+ int NumUsers = Users.GetNumKeys();
+ for (int i = 0; i < NumUsers; i++)
+ {
+ AString UserName = Users.GetKeyName(i);
+ AString lcUserName = StrToLower(UserName);
+ if (m_Users.find(lcUserName) != m_Users.end())
+ {
+ LOGINFO("users.ini contains a duplicate definition of user %s, ignoring the latter.", UserName.c_str());
+ continue;
+ }
+ m_Users[lcUserName] = sUser(
+ UserName,
+ StringSplitAndTrim(Users.GetValue(UserName, "Groups", ""), ",")
+ );
+ } // for i - Users' keys
+ return true;
+ }
+
+
+
+ /** Removes non-existent groups from each user's definition. */
+ void CleanUserGroups(void)
+ {
+ for (sUserMap::iterator itrU = m_Users.begin(), endU = m_Users.end(); itrU != endU; ++itrU)
+ {
+ AStringVector & Groups = itrU->second.m_Groups;
+ for (AStringVector::iterator itrG = Groups.begin(); itrG != Groups.end();)
+ {
+ AString lcGroup = StrToLower(*itrG);
+ if (m_Groups.find(lcGroup) != m_Groups.end())
+ {
+ // Assigned group exists, continue checking the next one
+ ++itrG;
+ continue;
+ }
+ // Assigned group doesn't exist, remove it from the list:
+ LOGWARNING("RankMigrator: User \"%s\" is assigned a non-existent group \"%s\", this assignment will be ignored.",
+ itrU->second.m_Name.c_str(), itrG->c_str()
+ );
+ AStringVector::iterator itrG2 = itrG;
+ ++itrG2;
+ Groups.erase(itrG);
+ itrG = itrG2;
+ } // for itrG - Groups[]
+ } // for itrU - m_Users[]
+ }
+
+
+
+ /** Creates groups based on m_Groups.
+ Ignores group inheritance. */
+ void CreateGroups(void)
+ {
+ // Create each group, with its permissions:
+ for (sGroupMap::const_iterator itr = m_Groups.begin(), end = m_Groups.end(); itr != end; ++itr)
+ {
+ m_RankManager.AddGroup(itr->second.m_Name);
+ m_RankManager.AddPermissionsToGroup(itr->second.m_Permissions, itr->second.m_Name);
+ } // for itr - m_Groups[]
+ }
+
+
+ /** Resolves the UUID of each user in m_Users.
+ If a user doesn't resolve, they are removed and logged in the console. */
+ void ResolveUserUUIDs(void)
+ {
+ // Resolve all PlayerNames at once (the API doesn't like single-name queries):
+ AStringVector PlayerNames;
+ for (sUserMap::const_iterator itr = m_Users.begin(), end = m_Users.end(); itr != end; ++itr)
+ {
+ PlayerNames.push_back(itr->second.m_Name);
+ }
+ m_MojangAPI.GetUUIDsFromPlayerNames(PlayerNames);
+
+ // Assign the UUIDs back to players, remove those not resolved:
+ for (sUserMap::iterator itr = m_Users.begin(); itr != m_Users.end(); )
+ {
+ AString UUID = m_MojangAPI.GetUUIDFromPlayerName(itr->second.m_Name);
+ if (UUID.empty())
+ {
+ LOGWARNING("RankMigrator: Cannot resolve player %s to UUID, player will be left unranked", itr->second.m_Name.c_str());
+ sUserMap::iterator itr2 = itr;
+ ++itr2;
+ m_Users.erase(itr);
+ itr = itr2;
+ }
+ else
+ {
+ itr->second.m_UUID = UUID;
+ ++itr;
+ }
+ }
+ }
+
+
+
+ /** Adds the specified groups to the specified ranks. Recurses on the groups' inheritance. */
+ void AddGroupsToRank(const AStringVector & a_Groups, const AString & a_RankName)
+ {
+ for (AStringVector::const_iterator itr = a_Groups.begin(), end = a_Groups.end(); itr != end; ++itr)
+ {
+ // Normalize the group name:
+ sGroup & Group = m_Groups[StrToLower(*itr)];
+
+ // Avoid loops, check if the group is already added:
+ if (m_RankManager.IsGroupInRank(Group.m_Name, a_RankName))
+ {
+ continue;
+ }
+
+ // Add the group, and all the groups it inherits from recursively:
+ m_RankManager.AddGroupToRank(Group.m_Name, a_RankName);
+ AddGroupsToRank(Group.m_Inherits, a_RankName);
+ } // for itr - a_Groups[]
+ }
+
+
+
+ /** Creates a rank for each player, based on the master groups they are assigned. */
+ void SetRanks(void)
+ {
+ for (sUserMap::const_iterator itr = m_Users.begin(), end = m_Users.end(); itr != end; ++itr)
+ {
+ // Ignore users with no groups:
+ const AStringVector & Groups = itr->second.m_Groups;
+ if (Groups.empty())
+ {
+ LOGWARNING("RankMigrator: Player %s has no groups assigned to them, skipping the player.", itr->second.m_Name.c_str());
+ continue;
+ }
+
+ // Compose the rank name out of group names:
+ AString RankName;
+ for (AStringVector::const_iterator itrG = Groups.begin(), endG = Groups.end(); itrG != endG; ++itrG)
+ {
+ AString GroupName = m_Groups[StrToLower(*itrG)].m_Name; // Normalize group name
+ if (!RankName.empty())
+ {
+ RankName.push_back(',');
+ }
+ RankName.append(GroupName);
+ } // for itrG - Groups[]
+
+ // Create the rank, with al its groups:
+ if (!m_RankManager.RankExists(RankName))
+ {
+ m_RankManager.AddRank(RankName, "", "", m_Groups[StrToLower(Groups[0])].m_Color);
+ AddGroupsToRank(Groups, RankName);
+ }
+
+ // Set the rank to the user:
+ m_RankManager.SetPlayerRank(itr->second.m_UUID, itr->second.m_Name, RankName);
+ } // for itr - m_Users[]
+ }
+};
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// cRankManager:
+
+cRankManager::cRankManager(void) :
+ m_DB("Ranks.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE),
+ m_IsInitialized(false)
+{
+}
+
+
+
+
+
+void cRankManager::Initialize(cMojangAPI & a_MojangAPI)
+{
+ ASSERT(!m_IsInitialized); // Calling Initialize for the second time?
+
// Create the DB tables, if they don't exist:
m_DB.exec("CREATE TABLE IF NOT EXISTS Rank (RankID INTEGER PRIMARY KEY, Name, MsgPrefix, MsgSuffix, MsgNameColorCode)");
m_DB.exec("CREATE TABLE IF NOT EXISTS PlayerRank (PlayerUUID, PlayerName, RankID INTEGER)");
@@ -229,6 +589,22 @@ cRankManager::cRankManager(void) :
m_DB.exec("CREATE TABLE IF NOT EXISTS RankPermGroup (RankID INTEGER, PermGroupID INTEGER)");
m_DB.exec("CREATE TABLE IF NOT EXISTS PermissionItem (PermGroupID INTEGER, Permission)");
+ m_IsInitialized = true;
+
+ // Check if tables empty, migrate from ini files then
+ if (AreDBTablesEmpty())
+ {
+ LOGINFO("There are no ranks, migrating old-style INI files to new DB ranks...");
+ LOGINFO("(This might take a while)");
+ cRankManagerIniMigrator Migrator(*this, a_MojangAPI);
+ if (Migrator.Migrate())
+ {
+ LOGINFO("Ranks migrated.");
+ return;
+ }
+ }
+
+ // Migration failed.
// TODO: Check if tables empty, add some defaults then
}
@@ -238,6 +614,8 @@ cRankManager::cRankManager(void) :
AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Statement stmt(m_DB, "SELECT Rank.Name FROM Rank LEFT JOIN PlayerRank ON Rank.RankID = PlayerRank.RankID WHERE PlayerRank.PlayerUUID = ?");
@@ -263,6 +641,8 @@ AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -296,6 +676,8 @@ AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -329,6 +711,8 @@ AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
AStringVector cRankManager::GetRankGroups(const AString & a_RankName)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -357,6 +741,8 @@ AStringVector cRankManager::GetRankGroups(const AString & a_RankName)
AStringVector cRankManager::GetGroupPermissions(const AString & a_GroupName)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -384,6 +770,8 @@ AStringVector cRankManager::GetGroupPermissions(const AString & a_GroupName)
AStringVector cRankManager::GetRankPermissions(const AString & a_RankName)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -412,6 +800,8 @@ AStringVector cRankManager::GetRankPermissions(const AString & a_RankName)
AStringVector cRankManager::GetAllRanks(void)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -434,6 +824,8 @@ AStringVector cRankManager::GetAllRanks(void)
AStringVector cRankManager::GetAllGroups(void)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -456,6 +848,8 @@ AStringVector cRankManager::GetAllGroups(void)
AStringVector cRankManager::GetAllPermissions(void)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -483,6 +877,8 @@ bool cRankManager::GetPlayerMsgVisuals(
AString & a_MsgNameColorCode
)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -526,6 +922,8 @@ void cRankManager::AddRank(
const AString & a_MsgNameColorCode
)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Check if such a rank name is already used:
@@ -566,6 +964,8 @@ void cRankManager::AddRank(
void cRankManager::AddGroup(const AString & a_GroupName)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Check if such a rank name is already used:
@@ -603,6 +1003,8 @@ void cRankManager::AddGroup(const AString & a_GroupName)
bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a_RankName)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Transaction trans(m_DB);
@@ -680,6 +1082,8 @@ bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a
bool cRankManager::AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Wrapp the entire operation into a transaction:
@@ -746,8 +1150,83 @@ bool cRankManager::AddPermissionToGroup(const AString & a_Permission, const AStr
+bool cRankManager::AddPermissionsToGroup(const AStringVector & a_Permissions, const AString & a_GroupName)
+{
+ ASSERT(m_IsInitialized);
+
+ try
+ {
+ // Wrapp the entire operation into a transaction:
+ SQLite::Transaction trans(m_DB);
+
+ // Get the group's ID:
+ int GroupID;
+ {
+ SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, a_GroupName);
+ if (!stmt.executeStep())
+ {
+ LOGWARNING("%s: No such group (%s), aborting.", __FUNCTION__, a_GroupName.c_str());
+ return false;
+ }
+ GroupID = stmt.getColumn(0).getInt();
+ }
+
+ for (AStringVector::const_iterator itr = a_Permissions.begin(), end = a_Permissions.end(); itr != end; ++itr)
+ {
+ // Check if the permission is already present:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermissionItem WHERE PermGroupID = ? AND Permission = ?");
+ stmt.bind(1, GroupID);
+ stmt.bind(2, *itr);
+ if (!stmt.executeStep())
+ {
+ LOGWARNING("%s: Failed to check binding between permission %s and group %s, aborting.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
+ return false;
+ }
+ if (stmt.getColumn(0).getInt() > 0)
+ {
+ LOGD("%s: Permission %s is already present in group %s, skipping and returning success.",
+ __FUNCTION__, itr->c_str(), a_GroupName.c_str()
+ );
+ continue;
+ }
+ }
+
+ // Add the permission:
+ {
+ SQLite::Statement stmt(m_DB, "INSERT INTO PermissionItem (Permission, PermGroupID) VALUES (?, ?)");
+ stmt.bind(1, *itr);
+ stmt.bind(2, GroupID);
+ if (stmt.exec() <= 0)
+ {
+ LOGWARNING("%s: Failed to add permission %s to group %s, skipping.", __FUNCTION__, itr->c_str(), a_GroupName.c_str());
+ continue;
+ }
+ }
+ } // for itr - a_Permissions[]
+
+ // Adding succeeded:
+ trans.commit();
+ return true;
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to add permissions to group %s: %s",
+ __FUNCTION__, a_GroupName.c_str(), ex.what()
+ );
+ }
+ return false;
+}
+
+
+
+
+
void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName)
{
+ ASSERT(m_IsInitialized);
+
AStringVector res;
try
{
@@ -823,6 +1302,8 @@ void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_Repl
void cRankManager::RemoveGroup(const AString & a_GroupName)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Wrap everything into a transaction:
@@ -876,6 +1357,8 @@ void cRankManager::RemoveGroup(const AString & a_GroupName)
void cRankManager::RemoveGroupFromRank(const AString & a_GroupName, const AString & a_RankName)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Wrap everything into a transaction:
@@ -930,6 +1413,8 @@ void cRankManager::RemoveGroupFromRank(const AString & a_GroupName, const AStrin
void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Wrap everything into a transaction:
@@ -972,6 +1457,8 @@ void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const
bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewName)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Wrap everything into a transaction:
@@ -1014,6 +1501,8 @@ bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewNa
bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewName)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Wrap everything into a transaction:
@@ -1056,6 +1545,8 @@ bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewN
void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName)
{
+ ASSERT(m_IsInitialized);
+
try
{
// Wrap the entire operation into a transaction:
@@ -1123,6 +1614,8 @@ void cRankManager::SetRankVisuals(
const AString & a_MsgNameColorCode
)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Statement stmt(m_DB, "UPDATE Rank SET MsgPrefix = ?, MsgSuffix = ?, MsgNameColorCode = ? WHERE Name = ?");
@@ -1152,6 +1645,8 @@ bool cRankManager::GetRankVisuals(
AString & a_MsgNameColorCode
)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Statement stmt(m_DB, "SELECT MsgPrefix, MsgSuffix, MsgNameColorCode FROM Rank WHERE Name = ?");
@@ -1179,6 +1674,8 @@ bool cRankManager::GetRankVisuals(
bool cRankManager::RankExists(const AString & a_RankName)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Statement stmt(m_DB, "SELECT * FROM Rank WHERE Name = ?");
@@ -1202,6 +1699,8 @@ bool cRankManager::RankExists(const AString & a_RankName)
bool cRankManager::GroupExists(const AString & a_GroupName)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Statement stmt(m_DB, "SELECT * FROM PermGroup WHERE Name = ?");
@@ -1225,6 +1724,8 @@ bool cRankManager::GroupExists(const AString & a_GroupName)
bool cRankManager::IsPlayerRankSet(const AString & a_PlayerUUID)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Statement stmt(m_DB, "SELECT * FROM PlayerRank WHERE PlayerUUID = ?");
@@ -1248,6 +1749,8 @@ bool cRankManager::IsPlayerRankSet(const AString & a_PlayerUUID)
bool cRankManager::IsGroupInRank(const AString & a_GroupName, const AString & a_RankName)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Statement stmt(m_DB,
@@ -1277,6 +1780,8 @@ bool cRankManager::IsGroupInRank(const AString & a_GroupName, const AString & a_
bool cRankManager::IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName)
{
+ ASSERT(m_IsInitialized);
+
try
{
SQLite::Statement stmt(m_DB,
@@ -1302,3 +1807,36 @@ bool cRankManager::IsPermissionInGroup(const AString & a_Permission, const AStri
+
+bool cRankManager::AreDBTablesEmpty(void)
+{
+ return (
+ IsDBTableEmpty("Rank") &&
+ IsDBTableEmpty("PlayerRank") &&
+ IsDBTableEmpty("PermGroup") &&
+ IsDBTableEmpty("RankPermGroup") &&
+ IsDBTableEmpty("PermissionItem")
+ );
+}
+
+
+
+
+
+bool cRankManager::IsDBTableEmpty(const AString & a_TableName)
+{
+ try
+ {
+ SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM " + a_TableName);
+ return (stmt.executeStep() && (stmt.getColumn(0).getInt() == 0));
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to query DB: %s", __FUNCTION__, ex.what());
+ }
+ return false;
+}
+
+
+
+
diff --git a/src/RankManager.h b/src/RankManager.h
index 0a43bfe5d..ffe7638e1 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -14,11 +14,22 @@
+class cMojangAPI;
+
+
+
+
+
class cRankManager
{
public:
+ /** Creates the rank manager. Needs to be initialized before other use. */
cRankManager(void);
+ /** Initializes the rank manager. Performs migration and default-setting if no data is found in the DB.
+ The a_MojangAPI param is used when migrating from old ini files, to look up player UUIDs. */
+ void Initialize(cMojangAPI & a_MojangAPI);
+
/** Returns the name of the rank that the specified player has assigned to them. */
AString GetPlayerRankName(const AString & a_PlayerUUID);
@@ -79,6 +90,11 @@ public:
Returns true if successful, false on error. */
bool AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName);
+ /** Adds the specified permissions to the specified permission group.
+ Fails if the permission group name is not found.
+ Returns true if successful, false on error. */
+ bool AddPermissionsToGroup(const AStringVector & a_Permissions, const AString & a_GroupName);
+
/** Removes the specified rank.
All players assigned to that rank will be re-assigned to a_ReplacementRankName.
If a_ReplacementRankName is empty or not a valid rank, the player will be removed from the DB,
@@ -147,7 +163,19 @@ public:
protected:
+ /** The database storage for all the data. */
SQLite::Database m_DB;
+
+ /** Set to true once the manager is initialized. */
+ bool m_IsInitialized;
+
+
+ /** Returns true if all the DB tables are empty, indicating a fresh new install. */
+ bool AreDBTablesEmpty(void);
+
+ /** Returns true iff the specified DB table is empty.
+ If there's an error while querying, returns false. */
+ bool IsDBTableEmpty(const AString & a_TableName);
} ;
diff --git a/src/Root.cpp b/src/Root.cpp
index c20cf0d21..333d92de5 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -156,6 +156,7 @@ void cRoot::Start(void)
m_WebAdmin->Init();
LOGD("Loading settings...");
+ m_RankManager.Initialize(m_MojangAPI);
m_GroupManager = new cGroupManager();
m_CraftingRecipes = new cCraftingRecipes;
m_FurnaceRecipe = new cFurnaceRecipe();
From 5e415c5b9565564c41c4f2f4144c6863c106bc46 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 13 Aug 2014 12:33:31 +0200
Subject: [PATCH 166/751] RankMgr: Fixed multithreading issues.
Only one thread is allowed to interact with a SQLite::Database object at a time.
Additionally, improved performance of the migration by wrapping the entire thing in a transaction.
---
src/RankManager.cpp | 128 +++++++++++++++++++++++++++-----------------
src/RankManager.h | 32 ++++++++++-
2 files changed, 110 insertions(+), 50 deletions(-)
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index 9809f1d6c..e64a47eb6 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -5,7 +5,6 @@
#include "Globals.h"
#include "RankManager.h"
-#include "SQLiteCpp/Transaction.h"
#include "inifile/iniFile.h"
#include "Protocol/MojangAPI.h"
@@ -237,6 +236,8 @@ public:
/** Performs the complete migration from INI files to DB. */
bool Migrate(void)
{
+ cRankManager::cMassChangeLock Lock(m_RankManager);
+
LOGD("Reading groups...");
if (!ReadGroups())
{
@@ -615,6 +616,7 @@ void cRankManager::Initialize(cMojangAPI & a_MojangAPI)
AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
@@ -642,6 +644,7 @@ AString cRankManager::GetPlayerRankName(const AString & a_PlayerUUID)
AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -677,6 +680,7 @@ AStringVector cRankManager::GetPlayerGroups(const AString & a_PlayerUUID)
AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -712,6 +716,7 @@ AStringVector cRankManager::GetPlayerPermissions(const AString & a_PlayerUUID)
AStringVector cRankManager::GetRankGroups(const AString & a_RankName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -742,6 +747,7 @@ AStringVector cRankManager::GetRankGroups(const AString & a_RankName)
AStringVector cRankManager::GetGroupPermissions(const AString & a_GroupName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -771,6 +777,7 @@ AStringVector cRankManager::GetGroupPermissions(const AString & a_GroupName)
AStringVector cRankManager::GetRankPermissions(const AString & a_RankName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -801,6 +808,7 @@ AStringVector cRankManager::GetRankPermissions(const AString & a_RankName)
AStringVector cRankManager::GetAllRanks(void)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -825,6 +833,7 @@ AStringVector cRankManager::GetAllRanks(void)
AStringVector cRankManager::GetAllGroups(void)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -849,6 +858,7 @@ AStringVector cRankManager::GetAllGroups(void)
AStringVector cRankManager::GetAllPermissions(void)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -878,6 +888,7 @@ bool cRankManager::GetPlayerMsgVisuals(
)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
@@ -923,6 +934,7 @@ void cRankManager::AddRank(
)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
@@ -965,10 +977,11 @@ void cRankManager::AddRank(
void cRankManager::AddGroup(const AString & a_GroupName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Check if such a rank name is already used:
+ // Check if such a group name is already used:
{
SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermGroup WHERE Name = ?");
stmt.bind(1, a_GroupName);
@@ -982,7 +995,7 @@ void cRankManager::AddGroup(const AString & a_GroupName)
}
}
- // Insert a new rank:
+ // Insert a new group:
SQLite::Statement stmt(m_DB, "INSERT INTO PermGroup (Name) VALUES (?)");
stmt.bind(1, a_GroupName);
if (stmt.exec() <= 0)
@@ -1001,16 +1014,58 @@ void cRankManager::AddGroup(const AString & a_GroupName)
-bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a_RankName)
+void cRankManager::AddGroups(const AStringVector & a_GroupNames)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
+
+ try
+ {
+ for (AStringVector::const_iterator itr = a_GroupNames.begin(), end = a_GroupNames.end(); itr != end; ++itr)
+ {
+ // Check if such the group name is already used:
+ {
+ SQLite::Statement stmt(m_DB, "SELECT COUNT(*) FROM PermGroup WHERE Name = ?");
+ stmt.bind(1, *itr);
+ if (stmt.executeStep())
+ {
+ if (stmt.getColumn(0).getInt() > 0)
+ {
+ // Group already exists, do nothing:
+ return;
+ }
+ }
+ }
+
+ // Insert a new group:
+ SQLite::Statement stmt(m_DB, "INSERT INTO PermGroup (Name) VALUES (?)");
+ stmt.bind(1, *itr);
+ if (stmt.exec() <= 0)
+ {
+ LOGWARNING("%s: Failed to add a new group \"%s\".", __FUNCTION__, itr->c_str());
+ return;
+ }
+ } // for itr - a_GroupNames[]
+ }
+ catch (const SQLite::Exception & ex)
+ {
+ LOGWARNING("%s: Failed to add new groups: %s", __FUNCTION__, ex.what());
+ }
+}
+
+
+
+
+
+bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a_RankName)
+{
+ ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- SQLite::Transaction trans(m_DB);
- int GroupID, RankID;
-
// Get the group's ID:
+ int GroupID;
{
SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
stmt.bind(1, a_GroupName);
@@ -1023,6 +1078,7 @@ bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a
}
// Get the rank's ID:
+ int RankID;
{
SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
stmt.bind(1, a_RankName);
@@ -1066,7 +1122,6 @@ bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a
}
// Adding succeeded:
- trans.commit();
return true;
}
catch (const SQLite::Exception & ex)
@@ -1083,12 +1138,10 @@ bool cRankManager::AddGroupToRank(const AString & a_GroupName, const AString & a
bool cRankManager::AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Wrapp the entire operation into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Get the group's ID:
int GroupID;
{
@@ -1134,7 +1187,6 @@ bool cRankManager::AddPermissionToGroup(const AString & a_Permission, const AStr
}
// Adding succeeded:
- trans.commit();
return true;
}
catch (const SQLite::Exception & ex)
@@ -1153,12 +1205,10 @@ bool cRankManager::AddPermissionToGroup(const AString & a_Permission, const AStr
bool cRankManager::AddPermissionsToGroup(const AStringVector & a_Permissions, const AString & a_GroupName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Wrapp the entire operation into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Get the group's ID:
int GroupID;
{
@@ -1207,7 +1257,6 @@ bool cRankManager::AddPermissionsToGroup(const AStringVector & a_Permissions, co
} // for itr - a_Permissions[]
// Adding succeeded:
- trans.commit();
return true;
}
catch (const SQLite::Exception & ex)
@@ -1226,13 +1275,11 @@ bool cRankManager::AddPermissionsToGroup(const AStringVector & a_Permissions, co
void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
AStringVector res;
try
{
- // Wrap everything into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Get the RankID for the rank being removed:
int RemoveRankID;
{
@@ -1287,8 +1334,6 @@ void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_Repl
stmt.bind(1, RemoveRankID);
stmt.exec();
}
-
- trans.commit();
}
catch (const SQLite::Exception & ex)
{
@@ -1303,12 +1348,10 @@ void cRankManager::RemoveRank(const AString & a_RankName, const AString & a_Repl
void cRankManager::RemoveGroup(const AString & a_GroupName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Wrap everything into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Get the ID of the group:
int GroupID;
{
@@ -1342,8 +1385,6 @@ void cRankManager::RemoveGroup(const AString & a_GroupName)
stmt.bind(1, GroupID);
stmt.exec();
}
-
- trans.commit();
}
catch (const SQLite::Exception & ex)
{
@@ -1358,12 +1399,10 @@ void cRankManager::RemoveGroup(const AString & a_GroupName)
void cRankManager::RemoveGroupFromRank(const AString & a_GroupName, const AString & a_RankName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Wrap everything into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Get the IDs of the group and the rank:
int GroupID, RankID;
{
@@ -1398,8 +1437,6 @@ void cRankManager::RemoveGroupFromRank(const AString & a_GroupName, const AStrin
stmt.bind(1, RankID);
stmt.exec();
}
-
- trans.commit();
}
catch (const SQLite::Exception & ex)
{
@@ -1414,12 +1451,10 @@ void cRankManager::RemoveGroupFromRank(const AString & a_GroupName, const AStrin
void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Wrap everything into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Get the ID of the group:
int GroupID;
{
@@ -1440,8 +1475,6 @@ void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const
stmt.bind(2, a_Permission);
stmt.exec();
}
-
- trans.commit();
}
catch (const SQLite::Exception & ex)
{
@@ -1458,12 +1491,10 @@ void cRankManager::RemovePermissionFromGroup(const AString & a_Permission, const
bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Wrap everything into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Check that NewName doesn't exist:
{
SQLite::Statement stmt(m_DB, "SELECT RankID FROM Rank WHERE Name = ?");
@@ -1484,7 +1515,6 @@ bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewNa
res = (stmt.exec() > 0);
}
- trans.commit();
return res;
}
catch (const SQLite::Exception & ex)
@@ -1502,12 +1532,10 @@ bool cRankManager::RenameRank(const AString & a_OldName, const AString & a_NewNa
bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Wrap everything into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Check that NewName doesn't exist:
{
SQLite::Statement stmt(m_DB, "SELECT PermGroupID FROM PermGroup WHERE Name = ?");
@@ -1528,7 +1556,6 @@ bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewN
res = (stmt.exec() > 0);
}
- trans.commit();
return res;
}
catch (const SQLite::Exception & ex)
@@ -1546,12 +1573,10 @@ bool cRankManager::RenameGroup(const AString & a_OldName, const AString & a_NewN
void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
- // Wrap the entire operation into a transaction:
- SQLite::Transaction trans(m_DB);
-
// Get the rank ID:
int RankID;
{
@@ -1574,7 +1599,6 @@ void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a
if (stmt.exec() > 0)
{
// Successfully updated the player's rank
- trans.commit();
return;
}
}
@@ -1587,7 +1611,6 @@ void cRankManager::SetPlayerRank(const AString & a_PlayerUUID, const AString & a
if (stmt.exec() > 0)
{
// Successfully added the player
- trans.commit();
return;
}
@@ -1615,6 +1638,7 @@ void cRankManager::SetRankVisuals(
)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
@@ -1646,6 +1670,7 @@ bool cRankManager::GetRankVisuals(
)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
@@ -1675,6 +1700,7 @@ bool cRankManager::GetRankVisuals(
bool cRankManager::RankExists(const AString & a_RankName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
@@ -1700,6 +1726,7 @@ bool cRankManager::RankExists(const AString & a_RankName)
bool cRankManager::GroupExists(const AString & a_GroupName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
@@ -1725,6 +1752,7 @@ bool cRankManager::GroupExists(const AString & a_GroupName)
bool cRankManager::IsPlayerRankSet(const AString & a_PlayerUUID)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
@@ -1750,6 +1778,7 @@ bool cRankManager::IsPlayerRankSet(const AString & a_PlayerUUID)
bool cRankManager::IsGroupInRank(const AString & a_GroupName, const AString & a_RankName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
@@ -1781,6 +1810,7 @@ bool cRankManager::IsGroupInRank(const AString & a_GroupName, const AString & a_
bool cRankManager::IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName)
{
ASSERT(m_IsInitialized);
+ cCSLock Lock(m_CS);
try
{
diff --git a/src/RankManager.h b/src/RankManager.h
index ffe7638e1..3ccbd2fd4 100644
--- a/src/RankManager.h
+++ b/src/RankManager.h
@@ -9,6 +9,7 @@
#pragma once
#include "SQLiteCpp/Database.h"
+#include "SQLiteCpp/Transaction.h"
@@ -23,6 +24,29 @@ class cMojangAPI;
class cRankManager
{
public:
+ /** Acquire this lock to perform mass changes.
+ Improves performance by wrapping everything into a transaction.
+ Makes sure that no other thread is accessing the DB. */
+ class cMassChangeLock
+ {
+ public:
+ cMassChangeLock(cRankManager & a_RankManager) :
+ m_Lock(a_RankManager.m_CS),
+ m_Transaction(a_RankManager.m_DB)
+ {
+ }
+
+ ~cMassChangeLock()
+ {
+ m_Transaction.commit();
+ }
+
+ protected:
+ cCSLock m_Lock;
+ SQLite::Transaction m_Transaction;
+ };
+
+
/** Creates the rank manager. Needs to be initialized before other use. */
cRankManager(void);
@@ -80,6 +104,9 @@ public:
/** Adds a new permission group. No action if such a group already exists. */
void AddGroup(const AString & a_GroupName);
+ /** Bulk-adds groups. Group names that already exist are silently skipped. */
+ void AddGroups(const AStringVector & a_GroupNames);
+
/** Adds the specified permission group to the specified rank.
Fails if the rank or group names are not found.
Returns true if successful, false on error. */
@@ -163,9 +190,12 @@ public:
protected:
- /** The database storage for all the data. */
+ /** The database storage for all the data. Protected by m_CS. */
SQLite::Database m_DB;
+ /** The mutex protecting m_DB against multi-threaded access. */
+ cCriticalSection m_CS;
+
/** Set to true once the manager is initialized. */
bool m_IsInitialized;
From 60ea4bb937ba56c6dcaf57dda377beed972cf0a5 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 13 Aug 2014 11:56:47 +0100
Subject: [PATCH 167/751] Removed unused method
---
src/WebAdmin.cpp | 22 ----------------------
src/WebAdmin.h | 3 ---
2 files changed, 25 deletions(-)
diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp
index ab6925e55..6882d7bc4 100644
--- a/src/WebAdmin.cpp
+++ b/src/WebAdmin.cpp
@@ -159,28 +159,6 @@ void cWebAdmin::Stop(void)
-AString cWebAdmin::GetTemplate()
-{
- AString retVal = "";
-
- char SourceFile[] = "webadmin/template.html";
-
- cFile f;
- if (!f.Open(SourceFile, cFile::fmRead))
- {
- return "";
- }
-
- // copy the file into the buffer:
- f.ReadRestOfFile(retVal);
-
- return retVal;
-}
-
-
-
-
-
void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
{
if (!a_Request.HasAuth())
diff --git a/src/WebAdmin.h b/src/WebAdmin.h
index f48e8ce9e..aefc1d145 100644
--- a/src/WebAdmin.h
+++ b/src/WebAdmin.h
@@ -208,9 +208,6 @@ protected:
/** The HTTP server which provides the underlying HTTP parsing, serialization and events */
cHTTPServer m_HTTPServer;
-
- AString GetTemplate(void);
-
/** Handles requests coming to the "/webadmin" or "/~webadmin" URLs */
void HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
From 2321d2af41e935d8353b18592c29d58c766a5658 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 13 Aug 2014 12:01:13 +0100
Subject: [PATCH 168/751] Fixed shadowing variable
---
src/WebAdmin.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp
index 6882d7bc4..23eedbd14 100644
--- a/src/WebAdmin.cpp
+++ b/src/WebAdmin.cpp
@@ -176,9 +176,9 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
}
// Check if the contents should be wrapped in the template:
- AString URL = a_Request.GetBareURL();
- ASSERT(URL.length() > 0);
- bool ShouldWrapInTemplate = ((URL.length() > 1) && (URL[1] != '~'));
+ AString BareURL = a_Request.GetBareURL();
+ ASSERT(BareURL.length() > 0);
+ bool ShouldWrapInTemplate = ((BareURL.length() > 1) && (BareURL[1] != '~'));
// Retrieve the request data:
cWebadminRequestData * Data = (cWebadminRequestData *)(a_Request.GetUserData());
@@ -193,7 +193,7 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
HTTPTemplateRequest TemplateRequest;
TemplateRequest.Request.Username = a_Request.GetAuthUsername();
TemplateRequest.Request.Method = a_Request.GetMethod();
- TemplateRequest.Request.Path = URL.substr(1);
+ TemplateRequest.Request.Path = BareURL.substr(1);
if (Data->m_Form.Finish())
{
@@ -236,7 +236,7 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
return;
}
- AString BaseURL = GetBaseURL(URL);
+ AString BaseURL = GetBaseURL(BareURL);
AString Menu;
Template = "{CONTENT}";
AString FoundPlugin;
From 8f7b9acb488a2dc4a9c34de499a3cd0e0829ef40 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 13 Aug 2014 12:10:21 +0100
Subject: [PATCH 169/751] Fixed forgotten error checking
---
src/CraftingRecipes.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 1a31a6e90..085b6e0d5 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -324,7 +324,11 @@ void cCraftingRecipes::LoadRecipes(void)
return;
}
AString Everything;
- f.ReadRestOfFile(Everything);
+ if (!f.ReadRestOfFile(Everything))
+ {
+ LOGWARNING("Cannot read file \"crafting.txt\", no crafting recipes will be available!");
+ return;
+ }
f.Close();
// Split it into lines, then process each line as a single recipe:
From c3c3d3a72d7517863f015364e62ca0dff46a6807 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 13 Aug 2014 12:14:55 +0100
Subject: [PATCH 170/751] Fixed type issues in CraftingRecipe.cpp
---
src/CraftingRecipes.cpp | 4 ++--
src/CraftingRecipes.h | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 085b6e0d5..48178eecb 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -83,7 +83,7 @@ cItem & cCraftingGrid::GetItem(int x, int y) const
-void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth)
+void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
{
// Accessible through scripting, must verify parameters:
if ((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height))
@@ -228,7 +228,7 @@ void cCraftingRecipe::Clear(void)
-void cCraftingRecipe::SetResult(ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth)
+void cCraftingRecipe::SetResult(ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
{
m_Result = cItem(a_ItemType, a_ItemCount, a_ItemHealth);
}
diff --git a/src/CraftingRecipes.h b/src/CraftingRecipes.h
index 0250d2f68..fe1e15817 100644
--- a/src/CraftingRecipes.h
+++ b/src/CraftingRecipes.h
@@ -33,7 +33,7 @@ public:
int GetWidth (void) const {return m_Width; }
int GetHeight(void) const {return m_Height; }
cItem & GetItem (int x, int y) const;
- void SetItem (int x, int y, ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth);
+ void SetItem (int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth);
void SetItem (int x, int y, const cItem & a_Item);
void Clear (void);
@@ -72,13 +72,13 @@ public:
int GetIngredientsHeight(void) const {return m_Ingredients.GetHeight(); }
cItem & GetIngredient (int x, int y) const {return m_Ingredients.GetItem(x, y); }
const cItem & GetResult (void) const {return m_Result; }
- void SetResult (ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth);
+ void SetResult (ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth);
void SetResult (const cItem & a_Item)
{
m_Result = a_Item;
}
- void SetIngredient (int x, int y, ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth)
+ void SetIngredient (int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
{
m_Ingredients.SetItem(x, y, a_ItemType, a_ItemCount, a_ItemHealth);
}
From 08c55ef98348b13f4375fe683337fbf3cc9a9122 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 13 Aug 2014 13:27:56 +0200
Subject: [PATCH 171/751] Logger: Fixed missing timestamp in log messages.
---
src/Logger.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Logger.cpp b/src/Logger.cpp
index 572a0e160..cb528e8ab 100644
--- a/src/Logger.cpp
+++ b/src/Logger.cpp
@@ -54,7 +54,7 @@ void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
cCSLock Lock(m_CriticalSection);
for (size_t i = 0; i < m_LogListeners.size(); i++)
{
- m_LogListeners[i]->Log(a_Message, a_LogLevel);
+ m_LogListeners[i]->Log(Line, a_LogLevel);
}
}
From 5921f78e523b3998e72f9c681b8211fd2bc99127 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 13 Aug 2014 13:28:45 +0200
Subject: [PATCH 172/751] Logger: Fixed windows debug ODS logger, fixed-size
file prefixes.
---
src/LoggerListeners.cpp | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/LoggerListeners.cpp b/src/LoggerListeners.cpp
index 912342a65..b86ab4127 100644
--- a/src/LoggerListeners.cpp
+++ b/src/LoggerListeners.cpp
@@ -17,6 +17,7 @@
class cColouredConsoleListener
: public cLogger::cListener
{
+ protected:
virtual void SetLogColour(cLogger::eLogLevel a_LogLevel) = 0;
virtual void SetDefaultLogColour() = 0;
@@ -24,7 +25,7 @@
virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override
{
SetLogColour(a_LogLevel);
- puts(a_Message.c_str());
+ fputs(a_Message.c_str(), stdout);
SetDefaultLogColour();
}
};
@@ -46,7 +47,7 @@
{
}
- #ifdef DEBUG
+ #ifdef _DEBUG
virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override
{
super::Log(a_Message, a_LogLevel);
@@ -289,31 +290,31 @@ cFileListener::cFileListener(void)
void cFileListener::Log(AString a_Message, cLogger::eLogLevel a_LogLevel)
{
- AString LogLevelString;
+ const char * LogLevelPrefix = "U ";
switch (a_LogLevel)
{
case cLogger::llRegular:
{
- LogLevelString = "Log";
+ LogLevelPrefix = " ";
break;
}
case cLogger::llInfo:
{
- LogLevelString = "Info";
+ LogLevelPrefix = "i ";
break;
}
case cLogger::llWarning:
{
- LogLevelString = "Warning";
+ LogLevelPrefix = "W ";
break;
}
case cLogger::llError:
{
- LogLevelString = "Error";
+ LogLevelPrefix = "E ";
break;
}
}
- m_File.Printf("%s: %s", LogLevelString.c_str(), a_Message.c_str());
+ m_File.Printf("%s: %s", LogLevelPrefix, a_Message.c_str());
}
From 36e918ce9bd546efa25987027a73e0f1d8fa192d Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 13 Aug 2014 13:31:19 +0200
Subject: [PATCH 173/751] File logger prefixes are 4 chars wide.
---
src/LoggerListeners.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/LoggerListeners.cpp b/src/LoggerListeners.cpp
index b86ab4127..836536cbd 100644
--- a/src/LoggerListeners.cpp
+++ b/src/LoggerListeners.cpp
@@ -290,31 +290,31 @@ cFileListener::cFileListener(void)
void cFileListener::Log(AString a_Message, cLogger::eLogLevel a_LogLevel)
{
- const char * LogLevelPrefix = "U ";
+ const char * LogLevelPrefix = "Unkn ";
switch (a_LogLevel)
{
case cLogger::llRegular:
{
- LogLevelPrefix = " ";
+ LogLevelPrefix = " ";
break;
}
case cLogger::llInfo:
{
- LogLevelPrefix = "i ";
+ LogLevelPrefix = "info ";
break;
}
case cLogger::llWarning:
{
- LogLevelPrefix = "W ";
+ LogLevelPrefix = "Warn ";
break;
}
case cLogger::llError:
{
- LogLevelPrefix = "E ";
+ LogLevelPrefix = "Err ";
break;
}
}
- m_File.Printf("%s: %s", LogLevelPrefix, a_Message.c_str());
+ m_File.Printf("%s%s", LogLevelPrefix, a_Message.c_str());
}
From 781e1e6264794ec0fddccd37a76f7a78a3fa8b09 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 13 Aug 2014 13:03:56 +0100
Subject: [PATCH 174/751] Fixed Integer pasing warnings in CraftingRecipies.cpp
---
src/CraftingRecipes.cpp | 6 ++--
src/StringUtils.h | 62 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 48178eecb..2d80ecaf8 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -392,8 +392,7 @@ void cCraftingRecipes::AddRecipeLine(int a_LineNum, const AString & a_RecipeLine
}
if (ResultSplit.size() > 1)
{
- Recipe->m_Result.m_ItemCount = atoi(ResultSplit[1].c_str());
- if (Recipe->m_Result.m_ItemCount == 0)
+ if (!StringToInteger(ResultSplit[1].c_str(), Recipe->m_Result.m_ItemCount))
{
LOGWARNING("crafting.txt: line %d: Cannot parse result count, ignoring the recipe.", a_LineNum);
LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str());
@@ -445,8 +444,7 @@ bool cCraftingRecipes::ParseItem(const AString & a_String, cItem & a_Item)
if (Split.size() > 1)
{
AString Damage = TrimString(Split[1]);
- a_Item.m_ItemDamage = atoi(Damage.c_str());
- if ((a_Item.m_ItemDamage == 0) && (Damage.compare("0") != 0))
+ if (!StringToInteger(Damage.c_str(), a_Item.m_ItemDamage))
{
// Parsing the number failed
return false;
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 142aaf59b..56ac83942 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -99,6 +99,68 @@ extern int GetBEInt(const char * a_Mem);
/// Writes four bytes to the specified memory location so that they interpret as BigEndian int
extern void SetBEInt(char * a_Mem, Int32 a_Value);
+/// Parses any integer type. Checks bounds and
+template
+bool StringToInteger(AString a_str, T& a_Num)
+{
+ size_t i = 0;
+ T positive = true;
+ T result = 0;
+ if (a_str[0] == '+')
+ {
+ i++;
+ }
+ else if (a_str[0] == '-')
+ {
+ i++;
+ positive = false;
+ }
+ if (positive)
+ {
+ for(; i <= a_str.size(); i++)
+ {
+ if ((a_str[i] <= '0') || (a_str[i] >= '9'))
+ {
+ return false;
+ }
+ if (std::numeric_limits::max() / 10 < result)
+ {
+ return false;
+ }
+ result *= 10;
+ T digit = a_str[i] - '0';
+ if (std::numeric_limits::max() - digit < result)
+ {
+ return false;
+ }
+ result += digit;
+ }
+ }
+ else
+ {
+ for(; i <= a_str.size(); i++)
+ {
+ if ((a_str[i] <= '0') || (a_str[i] >= '9'))
+ {
+ return false;
+ }
+ if (std::numeric_limits::min() / 10 > result)
+ {
+ return false;
+ }
+ result *= 10;
+ T digit = a_str[i] - '0';
+ if (std::numeric_limits::min() + digit > result)
+ {
+ return false;
+ }
+ result -= digit;
+ }
+ }
+ a_Num = result;
+ return true;
+}
+
// If you have any other string helper functions, declare them here
From fecd607d7496d77a488757871a5abe60f789572b Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 13 Aug 2014 13:15:29 +0100
Subject: [PATCH 175/751] Added missing header
---
src/StringUtils.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 56ac83942..30a193845 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -9,6 +9,7 @@
#pragma once
#include
+#include
From f4d268636a02346acc46c993666fe02bbc1ff0b8 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 13 Aug 2014 13:37:07 +0100
Subject: [PATCH 176/751] Fixed comments
---
src/StringUtils.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 30a193845..a78f8b0bf 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -100,12 +100,12 @@ extern int GetBEInt(const char * a_Mem);
/// Writes four bytes to the specified memory location so that they interpret as BigEndian int
extern void SetBEInt(char * a_Mem, Int32 a_Value);
-/// Parses any integer type. Checks bounds and
+/// Parses any integer type. Checks bounds and returns errors out of band.
template
-bool StringToInteger(AString a_str, T& a_Num)
+bool StringToInteger(const AString& a_str, T& a_Num)
{
size_t i = 0;
- T positive = true;
+ bool positive = true;
T result = 0;
if (a_str[0] == '+')
{
@@ -118,7 +118,7 @@ bool StringToInteger(AString a_str, T& a_Num)
}
if (positive)
{
- for(; i <= a_str.size(); i++)
+ for(size_t size = a_str.size(); i < size; i++)
{
if ((a_str[i] <= '0') || (a_str[i] >= '9'))
{
@@ -139,7 +139,7 @@ bool StringToInteger(AString a_str, T& a_Num)
}
else
{
- for(; i <= a_str.size(); i++)
+ for(size_t size = a_str.size(); i < size; i++)
{
if ((a_str[i] <= '0') || (a_str[i] >= '9'))
{
From a544c0238ba4c94d78692a7592107f8e510893ee Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Wed, 13 Aug 2014 18:53:23 +0200
Subject: [PATCH 177/751] Implement ability to push minecarts on curved rails
---
src/Entities/Minecart.cpp | 74 +++++++++++++++++++++++++++++++++++++--
1 file changed, 71 insertions(+), 3 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index d4eadc5d5..19eaa207f 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -871,11 +871,79 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
return true;
}
case E_META_RAIL_CURVED_ZM_XM:
- case E_META_RAIL_CURVED_ZM_XP:
- case E_META_RAIL_CURVED_ZP_XM:
case E_META_RAIL_CURVED_ZP_XP:
{
- // TODO - simply can't be bothered right now
+ Vector3d Distance(
+ MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(),
+ 0,
+ MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
+ );
+
+ if ( Distance.z == 0. ) Distance.z = 0.0001;
+ if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) )
+ {
+ if ( (-GetSpeedX() * 0.4) < 0.01 )
+ {
+ AddSpeedX( -4/sqrt(2) );
+ AddSpeedZ( 4/sqrt(2) );
+ }
+ else
+ {
+ SetSpeedX( -GetSpeedX() * 0.4 );
+ SetSpeedZ( GetSpeedZ() * 0.4 );
+ }
+ }
+ else
+ {
+ if ((GetSpeedX() * 0.4) < 0.01)
+ {
+ AddSpeedX( 4/sqrt(2) );
+ AddSpeedZ( -4/sqrt(2) );
+ }
+ else
+ {
+ SetSpeedX( GetSpeedX() * 0.4 );
+ SetSpeedZ( -GetSpeedZ() * 0.4 );
+ }
+ }
+ break;
+ }
+ case E_META_RAIL_CURVED_ZM_XP:
+ case E_META_RAIL_CURVED_ZP_XM:
+ {
+ Vector3d Distance(
+ MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(),
+ 0,
+ MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
+ );
+
+ if ( Distance.z == 0. ) Distance.z = 0.0001;
+ if ( ((Distance.z>=0)&&((Distance.x/Distance.z)<=-1)) || ((Distance.z<0)&&((Distance.x/Distance.z)>=-1)) )
+ {
+ if ( (GetSpeedX() * 0.4) < 0.01 )
+ {
+ AddSpeedX( 4/sqrt(2) );
+ AddSpeedZ( 4/sqrt(2) );
+ }
+ else
+ {
+ SetSpeedX( GetSpeedX() * 0.4 );
+ SetSpeedZ( GetSpeedZ() * 0.4 );
+ }
+ }
+ else
+ {
+ if ((-GetSpeedX() * 0.4) < 0.01)
+ {
+ AddSpeedX( -4/sqrt(2) );
+ AddSpeedZ( -4/sqrt(2) );
+ }
+ else
+ {
+ SetSpeedX( -GetSpeedX() * 0.4 );
+ SetSpeedZ( -GetSpeedZ() * 0.4 );
+ }
+ }
break;
}
default: break;
From 3698c5c8295e6a6a0f37b17f3c04bb118cc58bf6 Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Wed, 13 Aug 2014 19:16:00 +0200
Subject: [PATCH 178/751] Fixed braces and intendation errors
---
src/Entities/Minecart.cpp | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 19eaa207f..5cf56d3d2 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -879,8 +879,12 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
);
- if ( Distance.z == 0. ) Distance.z = 0.0001;
- if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) )
+ if ( Distance.z == 0. )
+ {
+ Distance.z = 0.0001;
+ }
+
+ if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) )
{
if ( (-GetSpeedX() * 0.4) < 0.01 )
{
@@ -917,7 +921,11 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
);
- if ( Distance.z == 0. ) Distance.z = 0.0001;
+ if ( Distance.z == 0. )
+ {
+ Distance.z = 0.0001;
+ }
+
if ( ((Distance.z>=0)&&((Distance.x/Distance.z)<=-1)) || ((Distance.z<0)&&((Distance.x/Distance.z)>=-1)) )
{
if ( (GetSpeedX() * 0.4) < 0.01 )
From 3f117897fbda4eec95ad5cdd728f197840dd7224 Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Wed, 13 Aug 2014 19:18:11 +0200
Subject: [PATCH 179/751] Another intendation error
---
src/Entities/Minecart.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 5cf56d3d2..cd5e2adaa 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -881,9 +881,9 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
if ( Distance.z == 0. )
{
- Distance.z = 0.0001;
+ Distance.z = 0.0001;
}
-
+
if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) )
{
if ( (-GetSpeedX() * 0.4) < 0.01 )
From 2d2d4ff33b74eefe053cce4d9a5daada65ed496b Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Wed, 13 Aug 2014 19:47:43 +0200
Subject: [PATCH 180/751] Further fixing of coding style errors
---
src/Entities/Minecart.cpp | 48 ++++++++++++++++++---------------------
1 file changed, 22 insertions(+), 26 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index cd5e2adaa..45b9782f3 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -879,14 +879,15 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
);
- if ( Distance.z == 0. )
+ if (Distance.z == 0.)
{
Distance.z = 0.0001;
}
- if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) )
+ if (((Distance.z >= 0) && ((Distance.x / Distance.z) >= 1)) ||
+ ((Distance.z<0) && ((Distance.x / Distance.z) <= 1)))
{
- if ( (-GetSpeedX() * 0.4) < 0.01 )
+ if ((-GetSpeedX() * 0.4) < 0.01)
{
AddSpeedX( -4/sqrt(2) );
AddSpeedZ( 4/sqrt(2) );
@@ -897,18 +898,15 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
SetSpeedZ( GetSpeedZ() * 0.4 );
}
}
+ else if ((GetSpeedX() * 0.4) < 0.01)
+ {
+ AddSpeedX( 4/sqrt(2) );
+ AddSpeedZ( -4/sqrt(2) );
+ }
else
{
- if ((GetSpeedX() * 0.4) < 0.01)
- {
- AddSpeedX( 4/sqrt(2) );
- AddSpeedZ( -4/sqrt(2) );
- }
- else
- {
- SetSpeedX( GetSpeedX() * 0.4 );
- SetSpeedZ( -GetSpeedZ() * 0.4 );
- }
+ SetSpeedX( GetSpeedX() * 0.4 );
+ SetSpeedZ( -GetSpeedZ() * 0.4 );
}
break;
}
@@ -921,14 +919,15 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
);
- if ( Distance.z == 0. )
+ if (Distance.z == 0.)
{
Distance.z = 0.0001;
}
- if ( ((Distance.z>=0)&&((Distance.x/Distance.z)<=-1)) || ((Distance.z<0)&&((Distance.x/Distance.z)>=-1)) )
+ if (((Distance.z >= 0) && ((Distance.x / Distance.z) <= -1)) ||
+ ((Distance.z<0) && ((Distance.x / Distance.z) >= -1)))
{
- if ( (GetSpeedX() * 0.4) < 0.01 )
+ if ((GetSpeedX() * 0.4) < 0.01)
{
AddSpeedX( 4/sqrt(2) );
AddSpeedZ( 4/sqrt(2) );
@@ -939,18 +938,15 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
SetSpeedZ( GetSpeedZ() * 0.4 );
}
}
+ else if ((-GetSpeedX() * 0.4) < 0.01)
+ {
+ AddSpeedX( -4/sqrt(2) );
+ AddSpeedZ( -4/sqrt(2) );
+ }
else
{
- if ((-GetSpeedX() * 0.4) < 0.01)
- {
- AddSpeedX( -4/sqrt(2) );
- AddSpeedZ( -4/sqrt(2) );
- }
- else
- {
- SetSpeedX( -GetSpeedX() * 0.4 );
- SetSpeedZ( -GetSpeedZ() * 0.4 );
- }
+ SetSpeedX( -GetSpeedX() * 0.4 );
+ SetSpeedZ( -GetSpeedZ() * 0.4 );
}
break;
}
From 008c1cdaf436dec2d7a4a925c6a600570594d6a2 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Thu, 14 Aug 2014 01:03:30 +0200
Subject: [PATCH 181/751] CheckBasicStyle checks the src folder as well.
---
src/CMakeLists.txt | 2 +-
src/Chunk.cpp | 26 ++++++++++++++++----------
src/Chunk.h | 2 +-
src/World.cpp | 2 +-
src/World.h | 2 +-
5 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index db9c61082..3994399f2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -234,7 +234,7 @@ endif()
# Generate a list of all source files:
-set(ALLFILES "")
+set(ALLFILES "${SRCS}" "${HDRS}")
foreach(folder ${FOLDERS})
get_directory_property(FOLDER_SRCS DIRECTORY ${folder} DEFINITION SRCS)
foreach (src ${FOLDER_SRCS})
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index a79a485a6..7bdf4196d 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -579,7 +579,7 @@ void cChunk::Tick(float a_Dt)
}
for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();)
- {
+ {
if (!((*itr)->IsMob())) // Mobs are ticked inside cWorld::TickMobs() (as we don't have to tick them if they are far away from players)
{
// Tick all entities in this chunk (except mobs):
@@ -594,17 +594,19 @@ void cChunk::Tick(float a_Dt)
itr = m_Entities.erase(itr);
delete ToDelete;
}
- else if ((*itr)->IsWorldTravellingFrom(m_World)) // Remove all entities that are travelling to another world:
+ else if ((*itr)->IsWorldTravellingFrom(m_World))
{
+ // Remove all entities that are travelling to another world
MarkDirty();
(*itr)->SetWorldTravellingFrom(NULL);
itr = m_Entities.erase(itr);
}
- else if ( // If any entity moved out of the chunk, move it to the neighbor:
+ else if (
((*itr)->GetChunkX() != m_PosX) ||
((*itr)->GetChunkZ() != m_PosZ)
)
{
+ // The entity moved out of the chunk, move it to the neighbor
MarkDirty();
MoveEntityToNewChunk(*itr);
itr = m_Entities.erase(itr);
@@ -885,14 +887,14 @@ void cChunk::ApplyWeatherToTop()
SetBlock(X, Height, Z, E_BLOCK_ICE, 0);
}
else if (
- (m_World->IsDeepSnowEnabled()) &&
- (
- (TopBlock == E_BLOCK_RED_ROSE) ||
- (TopBlock == E_BLOCK_YELLOW_FLOWER) ||
- (TopBlock == E_BLOCK_RED_MUSHROOM) ||
- (TopBlock == E_BLOCK_BROWN_MUSHROOM)
- )
+ (m_World->IsDeepSnowEnabled()) &&
+ (
+ (TopBlock == E_BLOCK_RED_ROSE) ||
+ (TopBlock == E_BLOCK_YELLOW_FLOWER) ||
+ (TopBlock == E_BLOCK_RED_MUSHROOM) ||
+ (TopBlock == E_BLOCK_BROWN_MUSHROOM)
)
+ )
{
SetBlock(X, Height, Z, E_BLOCK_SNOW, 0);
}
@@ -2142,10 +2144,14 @@ bool cChunk::DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_Blo
case E_BLOCK_DROPPER:
case E_BLOCK_DISPENSER:
case E_BLOCK_NOTE_BLOCK:
+ {
break;
+ }
default:
+ {
// There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out
return false;
+ }
}
if (a_Callback.Item((cRedstonePoweredEntity *)*itr))
diff --git a/src/Chunk.h b/src/Chunk.h
index 813a8b13f..72a1f6c95 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -241,7 +241,7 @@ public:
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
/** Calls the callback for the redstone powered entity at the specified coords; returns false if there's no redstone powered entity at those coords, true if found */
- bool DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cRedstonePoweredCallback & a_Callback);
+ bool DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cRedstonePoweredCallback & a_Callback);
/** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
diff --git a/src/World.cpp b/src/World.cpp
index 5298f3b03..b357b8a23 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -3327,7 +3327,7 @@ void cWorld::AddQueuedPlayers(void)
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = PlayersToAdd.begin(), end = PlayersToAdd.end(); itr != end; ++itr)
{
- ASSERT(std::find(m_Players.begin(), m_Players.end(), *itr) == m_Players.end()); // Is it already in the list? HOW?
+ ASSERT(std::find(m_Players.begin(), m_Players.end(), *itr) == m_Players.end()); // Is it already in the list? HOW?
LOGD("Adding player %s to world \"%s\".", (*itr)->GetName().c_str(), m_WorldName.c_str());
m_Players.push_back(*itr);
diff --git a/src/World.h b/src/World.h
index 6df1758e9..578c9682b 100644
--- a/src/World.h
+++ b/src/World.h
@@ -235,7 +235,7 @@ public:
void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) override; // tolua_export
+ virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) override; // tolua_export
void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export
void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL);
void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
From e3a74f379fc103f40e6bf85e626d7bac7db236af Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Thu, 14 Aug 2014 14:29:46 +0200
Subject: [PATCH 182/751] Further changes in coding style
---
src/Entities/Minecart.cpp | 66 +++++++++++++++++----------------------
1 file changed, 28 insertions(+), 38 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 45b9782f3..8e11d8a07 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -873,80 +873,70 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
case E_META_RAIL_CURVED_ZM_XM:
case E_META_RAIL_CURVED_ZP_XP:
{
- Vector3d Distance(
- MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(),
- 0,
- MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
- );
+ Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
- if (Distance.z == 0.)
- {
- Distance.z = 0.0001;
- }
+ Distance.z = std::max(Distance.z, 0.001);
- if (((Distance.z >= 0) && ((Distance.x / Distance.z) >= 1)) ||
- ((Distance.z<0) && ((Distance.x / Distance.z) <= 1)))
+ if (
+ ((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
+ ((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
+ )
{
if ((-GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX( -4/sqrt(2) );
- AddSpeedZ( 4/sqrt(2) );
+ AddSpeedX(-4/sqrt(2));
+ AddSpeedZ(4/sqrt(2));
}
else
{
- SetSpeedX( -GetSpeedX() * 0.4 );
- SetSpeedZ( GetSpeedZ() * 0.4 );
+ SetSpeedX(-GetSpeedX() * 0.4);
+ SetSpeedZ(GetSpeedZ() * 0.4);
}
}
else if ((GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX( 4/sqrt(2) );
- AddSpeedZ( -4/sqrt(2) );
+ AddSpeedX(4/sqrt(2));
+ AddSpeedZ(-4/sqrt(2));
}
else
{
- SetSpeedX( GetSpeedX() * 0.4 );
- SetSpeedZ( -GetSpeedZ() * 0.4 );
+ SetSpeedX(GetSpeedX() * 0.4);
+ SetSpeedZ(-GetSpeedZ() * 0.4);
}
break;
}
case E_META_RAIL_CURVED_ZM_XP:
case E_META_RAIL_CURVED_ZP_XM:
{
- Vector3d Distance(
- MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(),
- 0,
- MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
- );
+ Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
- if (Distance.z == 0.)
- {
- Distance.z = 0.0001;
- }
+ Distance.z = std::max(Distance.z, 0.001);
- if (((Distance.z >= 0) && ((Distance.x / Distance.z) <= -1)) ||
- ((Distance.z<0) && ((Distance.x / Distance.z) >= -1)))
+ if (
+ ((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
+ ((Distance.z < 0) && ((Distance.x / Distance.z) >= -1))
+ )
{
if ((GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX( 4/sqrt(2) );
- AddSpeedZ( 4/sqrt(2) );
+ AddSpeedX(4/sqrt(2));
+ AddSpeedZ(4/sqrt(2));
}
else
{
- SetSpeedX( GetSpeedX() * 0.4 );
- SetSpeedZ( GetSpeedZ() * 0.4 );
+ SetSpeedX(GetSpeedX() * 0.4);
+ SetSpeedZ(GetSpeedZ() * 0.4);
}
}
else if ((-GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX( -4/sqrt(2) );
- AddSpeedZ( -4/sqrt(2) );
+ AddSpeedX(-4/sqrt(2));
+ AddSpeedZ(-4/sqrt(2));
}
else
{
- SetSpeedX( -GetSpeedX() * 0.4 );
- SetSpeedZ( -GetSpeedZ() * 0.4 );
+ SetSpeedX(-GetSpeedX() * 0.4);
+ SetSpeedZ(-GetSpeedZ() * 0.4);
}
break;
}
From 3a7089539cc6be6e4ed00e17497e0dd327b9d67b Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Thu, 14 Aug 2014 23:06:46 +0200
Subject: [PATCH 183/751] RankMgr: Removed unneeded testing code.
---
src/RankManager.cpp | 210 +-------------------------------------------
1 file changed, 2 insertions(+), 208 deletions(-)
diff --git a/src/RankManager.cpp b/src/RankManager.cpp
index e64a47eb6..96c4baa56 100644
--- a/src/RankManager.cpp
+++ b/src/RankManager.cpp
@@ -12,215 +12,9 @@
-/*
-// This code is for internal testing while developing the cRankManager class
-static class cRankMgrTest
-{
-public:
- cRankMgrTest(void) :
- m_Mgr()
- {
- // Initialize logging:
- new cMCLogger();
- AString UUID = "b1caf24202a841a78055a079c460eee7"; // UUID for "xoft"
- LOG("Testing UUID %s", UUID.c_str());
-
- // Test the initial state of the ranks:
- LOG("Initial test:");
- ReportPlayer(UUID);
-
- // Add a rank, a few groups and permissions and set the player to use them:
- LOG("Adding data...");
- m_Mgr.AddRank("TestRank1", "[test]", "[/test]", "7");
- m_Mgr.AddRank("TestRank2", "[t2]", "[/t2]", "8");
- m_Mgr.AddGroup("TestGroup1");
- m_Mgr.AddGroup("TestGroup2");
- m_Mgr.AddGroupToRank("TestGroup1", "TestRank1");
- m_Mgr.AddGroupToRank("TestGroup2", "TestRank1");
- m_Mgr.AddGroupToRank("TestGroup2", "TestRank2");
- m_Mgr.AddPermissionToGroup("testpermission1.1", "TestGroup1");
- m_Mgr.AddPermissionToGroup("testpermission1.2", "TestGroup1");
- m_Mgr.AddPermissionToGroup("testpermission1.3", "TestGroup1");
- m_Mgr.AddPermissionToGroup("common", "TestGroup1");
- m_Mgr.AddPermissionToGroup("testpermission2.1", "TestGroup2");
- m_Mgr.AddPermissionToGroup("common", "TestGroup2");
- m_Mgr.SetPlayerRank(UUID, "xoft", "TestRank1");
-
- // Test the added data:
- LOG("Testing the added data:");
- LOG("IsGroupInRank(TestGroup1, TestRank1) = %s", m_Mgr.IsGroupInRank("TestGroup1", "TestRank1") ? "true" : "false");
- LOG("IsGroupInRank(TestGroup3, TestRank1) = %s", m_Mgr.IsGroupInRank("TestGroup3", "TestRank1") ? "true" : "false");
- LOG("IsPermissionInGroup(testpermission1.2, TestGroup1) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup1") ? "true" : "false"); // Existing permission, in group
- LOG("IsPermissionInGroup(testpermission1.2, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.2", "TestGroup2") ? "true" : "false"); // Existing permission, not in group
- LOG("IsPermissionInGroup(testpermission1.9, TestGroup2) = %s", m_Mgr.IsPermissionInGroup("testpermission1.9", "TestGroup2") ? "true" : "false"); // Non-existing permission
- LOG("IsPlayerRankSet(%s) = %s", UUID.c_str(), m_Mgr.IsPlayerRankSet(UUID) ? "true" : "false");
- LOG("IsPlayerRankSet(%s1) = %s", UUID.c_str(), m_Mgr.IsPlayerRankSet(UUID + "1") ? "true" : "false");
- LOG("GroupExists(TestGroup1) = %s", m_Mgr.GroupExists("TestGroup1") ? "true" : "false");
- LOG("GroupExists(TestGroup3) = %s", m_Mgr.GroupExists("TestGroup3") ? "true" : "false");
- LOG("RankExists(TestRank1) = %s", m_Mgr.RankExists("TestRank1") ? "true" : "false");
- LOG("RankExists(NonexistentRank) = %s", m_Mgr.RankExists("NonexistentRank") ? "true" : "false");
- ReportRankGroups("TestRank1");
- ReportRankGroups("NonexistentRank");
- ReportGroupPermissions("TestGroup1");
- ReportGroupPermissions("NonexistentGroup");
-
- // Report the contents of the DB:
- ReportAll();
-
- // Test the assignments above:
- LOG("After-assignment test:");
- ReportPlayer(UUID);
-
- // Test removing a permission from a group:
- LOG("Removing permission testpermission1.3 from group TestGroup1.");
- m_Mgr.RemovePermissionFromGroup("testpermission1.3", "TestGroup1");
- ReportGroupPermissions("TestGroup1");
- LOG("Removing permission common from group TestGroup1.");
- m_Mgr.RemovePermissionFromGroup("common", "TestGroup1");
- ReportGroupPermissions("TestGroup1"); // Check that it's not present
- ReportGroupPermissions("TestGroup2"); // Check that it's still present here
-
- // Test removing a group from rank:
- LOG("Removing group TestGroup2 from rank TestRank1.");
- m_Mgr.RemoveGroupFromRank("TestGroup2", "TestRank1");
- ReportRankGroups("TestRank1");
- LOG("Removing group TestGroup3 from rank TestRank1.");
- m_Mgr.RemoveGroupFromRank("TestGroup3", "TestRank1");
- ReportRankGroups("TestRank1");
-
- // Test re-adding the groups:
- LOG("Re-adding groups to TestRank1.");
- m_Mgr.AddGroupToRank("TestGroup1", "TestRank1");
- m_Mgr.AddGroupToRank("TestGroup2", "TestRank1");
- ReportRankGroups("TestRank1");
-
- // Test removing a group altogether:
- LOG("Removing group TestGroup2");
- m_Mgr.RemoveGroup("TestGroup2");
- ReportAll();
-
- // Test removing a rank:
- LOG("Removing rank TestRank2, replacing with rank TestRank1.");
- m_Mgr.RemoveRank("TestRank2", "TestRank1");
- ReportAll();
- LOG("Removing rank Test altogether.");
- m_Mgr.RemoveRank("Test", "");
- ReportAll();
-
- // Test renaming a rank:
- LOG("Renaming rank TestRank1 to Test");
- m_Mgr.RenameRank("TestRank1", "Test");
- ReportRankGroups("TestRank1");
- ReportRankGroups("Test");
- LOG("Player after renaming:");
- ReportPlayer(UUID);
-
- // Test renaming a group:
- LOG("Renaming group TestGroup1 to Test");
- m_Mgr.RenameGroup("TestGroup1", "Test");
- ReportGroupPermissions("TestGroup1");
- ReportGroupPermissions("Test");
- LOG("Player after renaming:");
- ReportPlayer(UUID);
- m_Mgr.RenameGroup("Test", "TestGroup1");
-
- // Test removing the rank in favor of another one:
- m_Mgr.RemoveRank("Test", "TestRank2");
- LOG("After-removal test:");
- ReportPlayer(UUID);
-
- LOG("Done.");
- }
-
-
- void ReportAll(void)
- {
- // Report all ranks:
- AStringVector Ranks = m_Mgr.GetAllRanks();
- LOG("All ranks (%u):", (unsigned)Ranks.size());
- for (AStringVector::const_iterator itr = Ranks.begin(), end = Ranks.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
-
- // Report all groups:
- AStringVector Groups = m_Mgr.GetAllGroups();
- LOG("All groups (%u):", (unsigned)Groups.size());
- for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
-
- // Report all permissions:
- AStringVector Permissions = m_Mgr.GetAllPermissions();
- LOG("All permissions (%u):", (unsigned)Permissions.size());
- for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
- }
-
-
- void ReportPlayer(const AString & a_PlayerUUID)
- {
- // Get the player's UUID and rank:
- LOG(" Rank: '%s'", m_Mgr.GetPlayerRankName(a_PlayerUUID).c_str());
-
- // List all the permission groups for the player:
- AStringVector Groups = m_Mgr.GetPlayerGroups(a_PlayerUUID);
- LOG(" Groups (%u):", (unsigned)Groups.size());
- for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
- {
- LOG(" '%s'" , itr->c_str());
- } // for itr - Groups[]
-
- // List all the permissions for the player:
- AStringVector Permissions = m_Mgr.GetPlayerPermissions(a_PlayerUUID);
- LOG(" Permissions (%u):", (unsigned)Permissions.size());
- for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- } // for itr - Groups[]
- }
-
-
- void ReportRankGroups(const AString & a_RankName)
- {
- AStringVector Groups = m_Mgr.GetRankGroups(a_RankName);
- LOG("Groups in rank %s: %u", a_RankName.c_str(), (unsigned)Groups.size());
- for (AStringVector::const_iterator itr = Groups.begin(), end = Groups.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
- AStringVector Permissions = m_Mgr.GetRankPermissions(a_RankName);
- LOG("Permissions in rank %s: %u", a_RankName.c_str(), (unsigned)Permissions.size());
- for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
- }
-
-
- void ReportGroupPermissions(const AString & a_GroupName)
- {
- AStringVector Permissions = m_Mgr.GetGroupPermissions(a_GroupName);
- LOG("Permissions in group %s: %u", a_GroupName.c_str(), (unsigned)Permissions.size());
- for (AStringVector::const_iterator itr = Permissions.begin(), end = Permissions.end(); itr != end; ++itr)
- {
- LOG(" '%s'", itr->c_str());
- }
- }
-
-protected:
- cRankManager m_Mgr;
-} g_RankMgrTest;
-//*/
-
-
-
-
-
////////////////////////////////////////////////////////////////////////////////
+// cRankManagerIniMigrator:
+
/** Migrates from groups.ini and users.ini into the rankmanager DB */
class cRankManagerIniMigrator
{
From 1f4a1383c2b261aa4644f8efeb31eedce4a62bf4 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 15 Aug 2014 07:19:13 +0200
Subject: [PATCH 184/751] Removed an unneeded cast.
---
src/OSSupport/File.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp
index af8a832f6..2194c46ee 100644
--- a/src/OSSupport/File.cpp
+++ b/src/OSSupport/File.cpp
@@ -259,7 +259,7 @@ int cFile::ReadRestOfFile(AString & a_Contents)
size_t DataSize = GetSize() - Tell();
// HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly
- a_Contents.assign((size_t)DataSize, '\0');
+ a_Contents.assign(DataSize, '\0');
return Read((void *)a_Contents.data(), DataSize);
}
From 0f631febfc3f670e8e9eb60ec4f89659ad7d0c71 Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Fri, 15 Aug 2014 13:40:56 +0200
Subject: [PATCH 185/751] Add some comments
---
src/Entities/Minecart.cpp | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 8e11d8a07..0455c9ab3 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -875,17 +875,23 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
+ // Prevent division by small numbers
Distance.z = std::max(Distance.z, 0.001);
+ /* Check to which side the minecart is to be pushed.
+ Let's consider a z-x-coordinate system where the minecart is the center (0/0).
+ The minecart moves along the line z = -x, the perpendicular line to this is z = x.
+ In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located.
+ */
if (
((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
)
{
- if ((-GetSpeedX() * 0.4) < 0.01)
+ if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
{
- AddSpeedX(-4/sqrt(2));
- AddSpeedZ(4/sqrt(2));
+ AddSpeedX(-4 / sqrt(2));
+ AddSpeedZ(4 / sqrt(2));
}
else
{
@@ -893,10 +899,10 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
SetSpeedZ(GetSpeedZ() * 0.4);
}
}
- else if ((GetSpeedX() * 0.4) < 0.01)
+ else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
{
- AddSpeedX(4/sqrt(2));
- AddSpeedZ(-4/sqrt(2));
+ AddSpeedX(4 / sqrt(2));
+ AddSpeedZ(-4 / sqrt(2));
}
else
{
@@ -910,8 +916,13 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
+ // Prevent division by small numbers
Distance.z = std::max(Distance.z, 0.001);
+ /* Check to which side the minecart is to be pushed.
+ Let's consider a z-x-coordinate system where the minecart is the center (0/0).
+ The minecart moves along the line z = x, the perpendicular line to this is z = -x.
+ In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
if (
((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) >= -1))
@@ -919,8 +930,8 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
if ((GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX(4/sqrt(2));
- AddSpeedZ(4/sqrt(2));
+ AddSpeedX(4 / sqrt(2));
+ AddSpeedZ(4 / sqrt(2));
}
else
{
@@ -930,8 +941,8 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
}
else if ((-GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX(-4/sqrt(2));
- AddSpeedZ(-4/sqrt(2));
+ AddSpeedX(-4 / sqrt(2));
+ AddSpeedZ(-4 / sqrt(2));
}
else
{
From be03b84048a49e04db11aa6ce80b3d18fff313b1 Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Fri, 15 Aug 2014 13:43:45 +0200
Subject: [PATCH 186/751] End of comment moved away from new line
---
src/Entities/Minecart.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 0455c9ab3..f190d972e 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -881,8 +881,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
The minecart moves along the line z = -x, the perpendicular line to this is z = x.
- In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located.
- */
+ In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
if (
((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
From c473d8cfb82009411f5a3977b7041ee49ba08003 Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Fri, 15 Aug 2014 14:00:51 +0200
Subject: [PATCH 187/751] Clarify comment message
---
src/Entities/Minecart.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index f190d972e..4753f720d 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -880,7 +880,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
- The minecart moves along the line z = -x, the perpendicular line to this is z = x.
+ The minecart moves along the line x = -z, the perpendicular line to this is x = z.
In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
if (
((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
@@ -920,7 +920,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
- The minecart moves along the line z = x, the perpendicular line to this is z = -x.
+ The minecart moves along the line x = z, the perpendicular line to this is x = -z.
In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
if (
((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
From 72c02ceb171949acd07338e77c8ee0d3439f8173 Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Fri, 15 Aug 2014 17:54:43 +0200
Subject: [PATCH 188/751] Added a lot of comments
---
src/Entities/Minecart.cpp | 66 +++++++++++++++++++++------------------
1 file changed, 36 insertions(+), 30 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 4753f720d..9420eca02 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -876,7 +876,10 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
- Distance.z = std::max(Distance.z, 0.001);
+ if (abs(Distance.z) < 0.001)
+ {
+ Distance.z = 0.001;
+ }
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
@@ -886,27 +889,27 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
)
- {
- if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
- {
+ { // Moving -X + Z
+ if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ speedX >= 0
+ { // Immobile or not moving in the "right" direction. Give it a bump!
AddSpeedX(-4 / sqrt(2));
AddSpeedZ(4 / sqrt(2));
}
- else
- {
- SetSpeedX(-GetSpeedX() * 0.4);
- SetSpeedZ(GetSpeedZ() * 0.4);
+ else // ~ SpeedX < 0
+ { // Moving in the "right" direction. Only accelerate it a bit.
+ SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
+ SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
- }
- else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
- {
+ } // Moving +X -Z
+ else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ SpeedX <= 0
+ { // Immobile or not moving in the "right" direction
AddSpeedX(4 / sqrt(2));
AddSpeedZ(-4 / sqrt(2));
}
- else
- {
- SetSpeedX(GetSpeedX() * 0.4);
- SetSpeedZ(-GetSpeedZ() * 0.4);
+ else // ~ SpeedX > 0
+ { // Moving in the "right" direction
+ SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
+ SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
break;
}
@@ -916,37 +919,40 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
- Distance.z = std::max(Distance.z, 0.001);
+ if (abs(Distance.z) < 0.001)
+ {
+ Distance.z = 0.001;
+ }
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
The minecart moves along the line x = z, the perpendicular line to this is x = -z.
In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
- if (
+ if ( // Moving +X +Z
((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) >= -1))
)
{
- if ((GetSpeedX() * 0.4) < 0.01)
- {
+ if ((GetSpeedX() * 0.4) < 0.01) // ~ SpeedX <= 0
+ { // Immobile or not moving in the "right" direction
AddSpeedX(4 / sqrt(2));
AddSpeedZ(4 / sqrt(2));
}
- else
- {
- SetSpeedX(GetSpeedX() * 0.4);
- SetSpeedZ(GetSpeedZ() * 0.4);
+ else // SpeedX > 0
+ { // Moving in the "right" direction
+ SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
+ SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
- }
- else if ((-GetSpeedX() * 0.4) < 0.01)
- {
+ } // Moving -X -Z
+ else if ((-GetSpeedX() * 0.4) < 0.01) // ~ SpeedX >= 0
+ { // Immobile or not moving in the "right" direction
AddSpeedX(-4 / sqrt(2));
AddSpeedZ(-4 / sqrt(2));
}
- else
- {
- SetSpeedX(-GetSpeedX() * 0.4);
- SetSpeedZ(-GetSpeedZ() * 0.4);
+ else // ~ SpeedX < 0
+ { // Moving in the "right" direction
+ SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
+ SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
break;
}
From 9395cf0bca15371b8dfdb7a444c1e9f7cca0252c Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 16 Aug 2014 18:02:16 +0200
Subject: [PATCH 189/751] First implementation of HOOK_SERVER_PING.
---
src/Bindings/Plugin.h | 1 +
src/Bindings/PluginLua.cpp | 20 ++++++++++++++++++++
src/Bindings/PluginLua.h | 1 +
src/Bindings/PluginManager.cpp | 19 +++++++++++++++++++
src/Bindings/PluginManager.h | 2 ++
5 files changed, 43 insertions(+)
diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h
index 39d53674b..6f05af51b 100644
--- a/src/Bindings/Plugin.h
+++ b/src/Bindings/Plugin.h
@@ -91,6 +91,7 @@ public:
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0;
virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos) = 0;
virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) = 0;
+ virtual bool OnServerPing (const AString & a_Username, AString & a_Motd, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon) = 0;
virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) = 0;
virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) = 0;
virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) = 0;
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 0f3f25d75..066e050d6 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -1193,6 +1193,26 @@ bool cPluginLua::OnProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity
+bool cPluginLua::OnServerPing(const AString & a_Username, AString & a_Motd, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon)
+{
+ cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_SERVER_PING];
+ for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
+ {
+ m_LuaState.Call((int)(**itr), a_Username, a_Motd, a_OnlinePlayersCount, a_MaxPlayersCount, a_Favicon, cLuaState::Return, res, a_Motd, a_OnlinePlayersCount, a_MaxPlayersCount, a_Favicon);
+ if (res)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginLua::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
{
cCSLock Lock(m_CriticalSection);
diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h
index 2cea644c1..2d98477f0 100644
--- a/src/Bindings/PluginLua.h
+++ b/src/Bindings/PluginLua.h
@@ -117,6 +117,7 @@ public:
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos) override;
virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) override;
+ virtual bool OnServerPing (const AString & a_Username, AString & a_Motd, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon) override;
virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) override;
virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) override;
virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) override;
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 89bfe3566..b9d28205d 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -1189,6 +1189,25 @@ bool cPluginManager::CallHookProjectileHitEntity(cProjectileEntity & a_Projectil
+bool cPluginManager::CallHookServerPing(const AString & a_Username, AString & a_Motd, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon)
+{
+ FIND_HOOK(HOOK_SERVER_PING);
+ VERIFY_HOOK;
+
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnServerPing(a_Username, a_Motd, a_OnlinePlayersCount, a_MaxPlayersCount, a_Favicon))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginManager::CallHookSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
{
FIND_HOOK(HOOK_SPAWNED_ENTITY);
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index 44a94e316..104e4c7a9 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -120,6 +120,7 @@ public:
HOOK_PRE_CRAFTING,
HOOK_PROJECTILE_HIT_BLOCK,
HOOK_PROJECTILE_HIT_ENTITY,
+ HOOK_SERVER_PING,
HOOK_SPAWNED_ENTITY,
HOOK_SPAWNED_MONSTER,
HOOK_SPAWNING_ENTITY,
@@ -225,6 +226,7 @@ public:
bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookProjectileHitBlock (cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos);
bool CallHookProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity);
+ bool CallHookServerPing (const AString & a_Username, AString & a_Motd, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon);
bool CallHookSpawnedEntity (cWorld & a_World, cEntity & a_Entity);
bool CallHookSpawnedMonster (cWorld & a_World, cMonster & a_Monster);
bool CallHookSpawningEntity (cWorld & a_World, cEntity & a_Entity);
From a68c70c900d0f3b3842d78af49423890f29af180 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 16 Aug 2014 18:44:14 +0200
Subject: [PATCH 190/751] Better OnPlayerMoving hook.
---
src/Bindings/Plugin.h | 2 +-
src/Bindings/PluginLua.cpp | 4 ++--
src/Bindings/PluginLua.h | 2 +-
src/Bindings/PluginManager.cpp | 4 ++--
src/Bindings/PluginManager.h | 2 +-
src/Entities/Player.cpp | 12 ++++++++++--
6 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h
index 39d53674b..2cc5cade3 100644
--- a/src/Bindings/Plugin.h
+++ b/src/Bindings/Plugin.h
@@ -73,7 +73,7 @@ public:
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) = 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 OnPlayerMoved (cPlayer & a_Player) = 0;
+ virtual bool OnPlayerMoving (cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition) = 0;
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual bool OnPlayerRightClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0;
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 0f3f25d75..37db78994 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -835,14 +835,14 @@ bool cPluginLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_Block
-bool cPluginLua::OnPlayerMoved(cPlayer & a_Player)
+bool cPluginLua::OnPlayerMoving(cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition)
{
cCSLock Lock(m_CriticalSection);
bool res = false;
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_MOVING];
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
{
- m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res);
+ m_LuaState.Call((int)(**itr), &a_Player, &a_OldPosition, &a_NewPosition, cLuaState::Return, res);
if (res)
{
return true;
diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h
index 2cea644c1..6df86f7a1 100644
--- a/src/Bindings/PluginLua.h
+++ b/src/Bindings/PluginLua.h
@@ -98,7 +98,7 @@ public:
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override;
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) override;
virtual bool OnPlayerJoined (cPlayer & a_Player) override;
- virtual bool OnPlayerMoved (cPlayer & a_Player) override;
+ virtual bool OnPlayerMoving (cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition) 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 OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 89bfe3566..dbc359f0e 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -849,14 +849,14 @@ bool cPluginManager::CallHookPlayerLeftClick(cPlayer & a_Player, int a_BlockX, i
-bool cPluginManager::CallHookPlayerMoving(cPlayer & a_Player)
+bool cPluginManager::CallHookPlayerMoving(cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition)
{
FIND_HOOK(HOOK_PLAYER_MOVING);
VERIFY_HOOK;
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
- if ((*itr)->OnPlayerMoved(a_Player))
+ if ((*itr)->OnPlayerMoving(a_Player, a_OldPosition, a_NewPosition))
{
return true;
}
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index 44a94e316..e0573f386 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -206,7 +206,7 @@ public:
bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward);
bool CallHookPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel);
bool CallHookPlayerJoined (cPlayer & a_Player);
- bool CallHookPlayerMoving (cPlayer & a_Player);
+ bool CallHookPlayerMoving (cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition);
bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
bool CallHookPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
bool CallHookPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 4398a5bf3..ab4ff3161 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -225,16 +225,24 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
SendExperience();
}
+ bool CanMove = true;
if (!GetPosition().EqualsEps(m_LastPos, 0.01)) // Non negligible change in position from last tick?
{
// Apply food exhaustion from movement:
ApplyFoodExhaustionFromMovement();
- cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this);
+ if (cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this, m_LastPos, GetPosition()))
+ {
+ CanMove = false;
+ TeleportToCoords(m_LastPos.x, m_LastPos.y, m_LastPos.z);
+ }
m_ClientHandle->StreamChunks();
}
- BroadcastMovementUpdate(m_ClientHandle);
+ if (CanMove)
+ {
+ BroadcastMovementUpdate(m_ClientHandle);
+ }
if (m_Health > 0) // make sure player is alive
{
From 6c8baf66c81e043710e70d8de584ab93d1cbbfc8 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 16 Aug 2014 18:49:24 +0200
Subject: [PATCH 191/751] Updated HOOK_PLAYER_MOVING documentation.
---
MCServer/Plugins/APIDump/Hooks/OnPlayerMoving.lua | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerMoving.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerMoving.lua
index 2756529ef..4385bf94d 100644
--- a/MCServer/Plugins/APIDump/Hooks/OnPlayerMoving.lua
+++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerMoving.lua
@@ -11,9 +11,11 @@ return
Params =
{
{ Name = "Player", Type = "{{cPlayer}}", Notes = "The player who has moved. The object already has the new position stored in it." },
+ { Name = "OldPosition", Type = "{{Vector3d}}", Notes = "The old position." },
+ { Name = "NewPosition", Type = "{{Vector3d}}", Notes = "The new position." },
},
Returns = [[
- If the function returns true, movement is prohibited. FIXME: The player's client is not informed.
+ If the function returns true, movement is prohibited.
If the function returns false or no value, other plugins' callbacks are called and finally the new
position is permanently stored in the cPlayer object.
From 9522bd842ea845cc37b4d2a60333453c12b024a4 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Mon, 18 Aug 2014 12:53:36 +0200
Subject: [PATCH 192/751] SwamplandM: Fixed sometimes having no mountains.
---
src/Generating/HeiGen.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp
index ba11b31b4..c3f3b38a9 100644
--- a/src/Generating/HeiGen.cpp
+++ b/src/Generating/HeiGen.cpp
@@ -432,7 +432,7 @@ const cHeiGenBiomal::sGenParam cHeiGenBiomal::m_GenParam[256] =
/* biExtremeHillsM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 131
/* biFlowerForest */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 132
/* biTaigaM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 133
- /* biSwamplandM */ { 1.0f, 2.0f, 1.10f, 5.0f, 0.01f, 8.0f, 60}, // 134
+ /* biSwamplandM */ { 1.0f, 3.0f, 1.10f, 7.0f, 0.01f, 0.01f, 60}, // 134
// Biomes 135 .. 139 unused, 5 empty placeholders here:
{}, {}, {}, {}, {}, // 135 .. 139
From 80559406f99bd32de066c8a80b9f920b8b57b8f1 Mon Sep 17 00:00:00 2001
From: Mattes D
Date: Sun, 17 Aug 2014 22:47:00 +0200
Subject: [PATCH 193/751] Player saving creates the "players" folder, if
needed.
Fixes #1268.
---
src/Entities/Player.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index ab4ff3161..0b13e62a9 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1842,6 +1842,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
bool cPlayer::SaveToDisk()
{
+ cFile::CreateFolder(FILE_IO_PREFIX + AString("players/")); // Create the "players" folder, if it doesn't exist yet (#1268)
cFile::CreateFolder(FILE_IO_PREFIX + AString("players/") + m_UUID.substr(0, 2));
// create the JSON data
From c70886a7124e5940b67cb4f1b4593f103f2707d8 Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Mon, 18 Aug 2014 01:57:44 +0200
Subject: [PATCH 194/751] Adjust comment formatting
---
src/Entities/Minecart.cpp | 60 ++++++++++++++++++++++++++-------------
1 file changed, 40 insertions(+), 20 deletions(-)
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 9420eca02..13469edb3 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -889,25 +889,35 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
)
- { // Moving -X + Z
- if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ speedX >= 0
- { // Immobile or not moving in the "right" direction. Give it a bump!
+ // Moving -X +Z
+ {
+ if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
+ // ~ speedX >= 0
+ {
+ // Immobile or not moving in the "right" direction. Give it a bump!
AddSpeedX(-4 / sqrt(2));
AddSpeedZ(4 / sqrt(2));
}
- else // ~ SpeedX < 0
- { // Moving in the "right" direction. Only accelerate it a bit.
+ else
+ // ~ SpeedX < 0
+ {
+ // Moving in the "right" direction. Only accelerate it a bit.
SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
- } // Moving +X -Z
- else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ SpeedX <= 0
- { // Immobile or not moving in the "right" direction
+ }
+ else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
+ // Moving +X -Z
+ // ~ SpeedX <= 0
+ {
+ // Immobile or not moving in the "right" direction
AddSpeedX(4 / sqrt(2));
AddSpeedZ(-4 / sqrt(2));
}
- else // ~ SpeedX > 0
- { // Moving in the "right" direction
+ else
+ // ~ SpeedX > 0
+ {
+ // Moving in the "right" direction
SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
@@ -928,29 +938,39 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
The minecart moves along the line x = z, the perpendicular line to this is x = -z.
In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
- if ( // Moving +X +Z
+ if (
((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) >= -1))
)
+ // Moving +X +Z
{
- if ((GetSpeedX() * 0.4) < 0.01) // ~ SpeedX <= 0
- { // Immobile or not moving in the "right" direction
+ if ((GetSpeedX() * 0.4) < 0.01)
+ // ~ SpeedX <= 0
+ {
+ // Immobile or not moving in the "right" direction
AddSpeedX(4 / sqrt(2));
AddSpeedZ(4 / sqrt(2));
}
- else // SpeedX > 0
- { // Moving in the "right" direction
+ else
+ // SpeedX > 0
+ {
+ // Moving in the "right" direction
SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
- } // Moving -X -Z
- else if ((-GetSpeedX() * 0.4) < 0.01) // ~ SpeedX >= 0
- { // Immobile or not moving in the "right" direction
+ }
+ else if ((-GetSpeedX() * 0.4) < 0.01)
+ // Moving -X -Z
+ // ~ SpeedX >= 0
+ {
+ // Immobile or not moving in the "right" direction
AddSpeedX(-4 / sqrt(2));
AddSpeedZ(-4 / sqrt(2));
}
- else // ~ SpeedX < 0
- { // Moving in the "right" direction
+ else
+ // ~ SpeedX < 0
+ {
+ // Moving in the "right" direction
SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
From e4fc05574bc4d888a8794d68c518e5242c494f69 Mon Sep 17 00:00:00 2001
From: Mattes D