From 4271d719b68521f91770574b3064525512116670 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 7 Aug 2014 01:07:32 +0200
Subject: [PATCH 01/28] 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 32e1e9a5536f92d074d51cca207f21c372973629 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 8 Aug 2014 18:38:20 +0200
Subject: [PATCH 02/28] 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 cccc321384be18d4ac75e83abf3ce4d19a2a3d56 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 10 Aug 2014 16:46:03 +0200
Subject: [PATCH 03/28] 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 04/28] 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 42bad0edec58f42e4072360c52870d3be9ced3c5 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sun, 10 Aug 2014 20:06:03 +0200
Subject: [PATCH 05/28] 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 06/28] 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 07/28] 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 08/28] 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 47c928cab7d1ff73e50925bc7ef50586b6ec9821 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Mon, 11 Aug 2014 00:20:28 +0200
Subject: [PATCH 09/28] 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 0a52ed6eb97ca5cc08fe255bfd04f78b4ea19a7e Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 11 Aug 2014 15:33:20 +0200
Subject: [PATCH 10/28] 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 f7726317c9c1c27fa3d0b9b7c2df35ffff6f1f1a Mon Sep 17 00:00:00 2001
From: Christophe Piveteau
Date: Mon, 11 Aug 2014 18:57:41 +0200
Subject: [PATCH 11/28] 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 98443682671d0c39b19f86098f7bc900b7529b72 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Tue, 12 Aug 2014 16:05:04 +0100
Subject: [PATCH 12/28] 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 13/28] 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 14/28] 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 60ea4bb937ba56c6dcaf57dda377beed972cf0a5 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Wed, 13 Aug 2014 11:56:47 +0100
Subject: [PATCH 15/28] 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 16/28] 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 08c55ef98348b13f4375fe683337fbf3cc9a9122 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 13 Aug 2014 13:27:56 +0200
Subject: [PATCH 17/28] 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 18/28] 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 19/28] 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 008c1cdaf436dec2d7a4a925c6a600570594d6a2 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Thu, 14 Aug 2014 01:03:30 +0200
Subject: [PATCH 20/28] 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 1f4a1383c2b261aa4644f8efeb31eedce4a62bf4 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 15 Aug 2014 07:19:13 +0200
Subject: [PATCH 21/28] 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 a68c70c900d0f3b3842d78af49423890f29af180 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 16 Aug 2014 18:44:14 +0200
Subject: [PATCH 22/28] 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 23/28] 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 24/28] 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 25/28] 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 e4fc05574bc4d888a8794d68c518e5242c494f69 Mon Sep 17 00:00:00 2001
From: Mattes D
Date: Mon, 18 Aug 2014 22:48:15 +0200
Subject: [PATCH 26/28] Player: Silenced a few type conversion warnings.
---
src/Entities/Player.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 0b13e62a9..32290885d 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -892,7 +892,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
Pickups.Add(cItem(E_ITEM_RED_APPLE));
}
- m_Stats.AddValue(statItemsDropped, Pickups.Size());
+ m_Stats.AddValue(statItemsDropped, (StatValue)Pickups.Size());
m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
SaveToDisk(); // Save it, yeah the world is a tough place !
@@ -1618,7 +1618,7 @@ void cPlayer::TossPickup(const cItem & a_Item)
void cPlayer::TossItems(const cItems & a_Items)
{
- m_Stats.AddValue(statItemsDropped, a_Items.Size());
+ m_Stats.AddValue(statItemsDropped, (StatValue)a_Items.Size());
double vX = 0, vY = 0, vZ = 0;
EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
From b5ffe06f884221f98407910bdd30baf533d84970 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Tue, 19 Aug 2014 22:14:37 +0200
Subject: [PATCH 27/28] Code formatting fixes.
---
src/Blocks/BlockBigFlower.h | 6 ++---
src/Blocks/BlockCake.h | 2 +-
src/Blocks/BlockDirt.h | 2 +-
src/Blocks/BlockFarmland.h | 5 +---
src/Blocks/BlockFenceGate.h | 1 +
src/Blocks/BlockFire.h | 25 +++++++++++-------
src/Blocks/BlockFlower.h | 2 +-
src/Blocks/BlockGlowstone.h | 6 ++---
src/Blocks/BlockHandler.cpp | 6 ++---
src/Blocks/BlockMelon.h | 4 +--
src/Blocks/BlockNewLeaves.h | 42 ------------------------------
src/Blocks/BlockNote.h | 13 ---------
src/Blocks/BlockOre.h | 40 ++++++++--------------------
src/Blocks/BlockPlanks.h | 3 +--
src/Blocks/BlockPortal.h | 8 +++---
src/Blocks/BlockPressurePlate.h | 4 +--
src/Blocks/BlockQuartz.h | 1 +
src/Blocks/BlockRedstone.h | 4 +--
src/Blocks/BlockRedstoneRepeater.h | 6 ++---
src/Blocks/BlockStairs.h | 20 +++++++-------
src/Blocks/BlockSugarcane.h | 1 +
src/Blocks/BlockTorch.h | 4 +--
src/Blocks/BlockTrapdoor.h | 9 ++++---
src/Blocks/BlockTripwireHook.h | 10 +++----
src/Blocks/BlockVine.h | 6 ++---
src/Chunk.cpp | 1 +
src/Items/ItemGoldenApple.h | 2 +-
src/Items/ItemShovel.h | 1 -
src/World.cpp | 1 +
29 files changed, 83 insertions(+), 152 deletions(-)
delete mode 100644 src/Blocks/BlockNewLeaves.h
delete mode 100644 src/Blocks/BlockNote.h
diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h
index 0b6ac9d8a..72e552dee 100644
--- a/src/Blocks/BlockBigFlower.h
+++ b/src/Blocks/BlockBigFlower.h
@@ -37,7 +37,7 @@ public:
{
NIBBLETYPE Meta = a_BlockMeta & 0x7;
- if ((Meta == 2) || (Meta == 3))
+ if ((Meta == E_META_BIG_FLOWER_DOUBLE_TALL_GRASS) || (Meta == E_META_BIG_FLOWER_LARGE_FERN))
{
return;
}
@@ -63,11 +63,11 @@ public:
if (r1.randInt(10) == 5)
{
cItems Pickups;
- if (FlowerMeta == 2)
+ if (FlowerMeta == E_META_BIG_FLOWER_DOUBLE_TALL_GRASS)
{
Pickups.Add(E_BLOCK_TALL_GRASS, 2, 1);
}
- else if (FlowerMeta == 3)
+ else if (FlowerMeta == E_META_BIG_FLOWER_LARGE_FERN)
{
Pickups.Add(E_BLOCK_TALL_GRASS, 2, 2);
}
diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h
index 36e133388..f05f468e5 100644
--- a/src/Blocks/BlockCake.h
+++ b/src/Blocks/BlockCake.h
@@ -19,7 +19,7 @@ public:
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- if (!a_Player->Feed(2, 0.1))
+ if (!a_Player->Feed(2, 0.4))
{
return;
}
diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h
index 2d4fccbac..d458c6062 100644
--- a/src/Blocks/BlockDirt.h
+++ b/src/Blocks/BlockDirt.h
@@ -81,7 +81,7 @@ public:
Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta);
if (cBlockInfo::GetHandler(AboveDest)->CanDirtGrowGrass(AboveMeta))
{
- if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, BlockX * cChunkDef::Width, BlockY, BlockZ * cChunkDef::Width, ssGrassSpread))
+ if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread(Chunk->GetWorld(), Chunk->GetPosX() * cChunkDef::Width + BlockX, BlockY, Chunk->GetPosZ() * cChunkDef::Width + BlockZ, ssGrassSpread))
{
Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0);
}
diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h
index ed0592acd..bb624e54f 100644
--- a/src/Blocks/BlockFarmland.h
+++ b/src/Blocks/BlockFarmland.h
@@ -54,10 +54,7 @@ public:
BLOCKTYPE * BlockTypes = Area.GetBlockTypes();
for (size_t i = 0; i < NumBlocks; i++)
{
- if (
- (BlockTypes[i] == E_BLOCK_WATER) ||
- (BlockTypes[i] == E_BLOCK_STATIONARY_WATER)
- )
+ if (IsBlockWater(BlockTypes[i]))
{
Found = true;
break;
diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h
index 433531275..ae99a4f94 100644
--- a/src/Blocks/BlockFenceGate.h
+++ b/src/Blocks/BlockFenceGate.h
@@ -35,6 +35,7 @@ public:
NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
NIBBLETYPE NewMetaData = PlayerYawToMetaData(a_Player->GetYaw());
OldMetaData ^= 4; // Toggle the gate
+
if ((OldMetaData & 1) == (NewMetaData & 1))
{
// Standing in front of the gate - apply new direction
diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h
index f52825362..c6a3e62cf 100644
--- a/src/Blocks/BlockFire.h
+++ b/src/Blocks/BlockFire.h
@@ -60,8 +60,8 @@ public:
return "step.wood";
}
- /// Traces along YP until it finds an obsidian block, returns Y difference or 0 if no portal, and -1 for border
- /// Takes the X, Y, and Z of the base block; with an optional MaxY for portal border finding
+ /** Traces along YP until it finds an obsidian block, returns Y difference or 0 if no portal, and -1 for border
+ Takes the X, Y, and Z of the base block; with an optional MaxY for portal border finding */
int FindObsidianCeiling(int X, int Y, int Z, cChunkInterface & a_ChunkInterface, int MaxY = 0)
{
if (a_ChunkInterface.GetBlock(X, Y, Z) != E_BLOCK_OBSIDIAN)
@@ -91,13 +91,12 @@ public:
return newY;
}
}
- else { return 0; }
}
return 0;
}
- /// Evaluates if coords have a valid border on top, based on MaxY
+ /** Evaluates if coords have a valid border on top, based on MaxY */
bool EvaluatePortalBorder(int X, int FoundObsidianY, int Z, int MaxY, cChunkInterface & a_ChunkInterface)
{
for (int checkBorder = FoundObsidianY + 1; checkBorder <= MaxY - 1; checkBorder++) // FoundObsidianY + 1: FoundObsidianY has already been checked in FindObsidianCeiling; MaxY - 1: portal doesn't need corners
@@ -149,8 +148,8 @@ public:
return;
}
- /// Evaluates if coordinates are a portal going XP/XM; returns true if so, and writes boundaries to variable
- /// Takes coordinates of base block and Y coord of target obsidian ceiling
+ /** Evaluates if coordinates are a portal going XP/XM; returns true if so, and writes boundaries to variable
+ Takes coordinates of base block and Y coord of target obsidian ceiling */
bool FindPortalSliceX(int X1, int X2, int Y, int Z, int MaxY, cChunkInterface & a_ChunkInterface)
{
Dir = 1; // Set assumed direction (will change if portal turns out to be facing the other direction)
@@ -168,7 +167,8 @@ public:
{
return false; // Not valid slice, no portal can be formed
}
- } XZP = X1 - 1; // Set boundary of frame interior
+ }
+ XZP = X1 - 1; // Set boundary of frame interior
for (; ((a_ChunkInterface.GetBlock(X2, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X2, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X2--) // Go the other direction (XM)
{
int Value = FindObsidianCeiling(X2, Y, Z, a_ChunkInterface, MaxY);
@@ -182,7 +182,9 @@ public:
{
return false;
}
- } XZM = X2 + 1; // Set boundary, see previous
+ }
+ XZM = X2 + 1; // Set boundary, see previous
+
return (FoundFrameXP && FoundFrameXM);
}
@@ -204,7 +206,8 @@ public:
{
return false;
}
- } XZP = Z1 - 1;
+ }
+ XZP = Z1 - 1;
for (; ((a_ChunkInterface.GetBlock(X, Y, Z2) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X, Y + 1, Z2) == E_BLOCK_OBSIDIAN)); Z2--)
{
int Value = FindObsidianCeiling(X, Y, Z2, a_ChunkInterface, MaxY);
@@ -218,7 +221,9 @@ public:
{
return false;
}
- } XZM = Z2 + 1;
+ }
+ XZM = Z2 + 1;
+
return (FoundFrameZP && FoundFrameZM);
}
};
diff --git a/src/Blocks/BlockFlower.h b/src/Blocks/BlockFlower.h
index e8fd4c7f6..6f64c062b 100644
--- a/src/Blocks/BlockFlower.h
+++ b/src/Blocks/BlockFlower.h
@@ -19,7 +19,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- // Reset meta to 0
+ // Reset meta to zero
a_Pickups.push_back(cItem(m_BlockType, 1, 0));
}
diff --git a/src/Blocks/BlockGlowstone.h b/src/Blocks/BlockGlowstone.h
index 6c198efc4..d1353e29a 100644
--- a/src/Blocks/BlockGlowstone.h
+++ b/src/Blocks/BlockGlowstone.h
@@ -15,13 +15,13 @@ public:
: cBlockHandler(a_BlockType)
{
}
-
+
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to 0
- MTRand r1;
- a_Pickups.push_back(cItem(E_ITEM_GLOWSTONE_DUST, (char)(2 + r1.randInt(2)), 0));
+ cFastRandom Random;
+ a_Pickups.push_back(cItem(E_ITEM_GLOWSTONE_DUST, (char)(2 + Random.NextInt(3)), 0));
}
} ;
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index 52f7dd608..028277e4c 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -45,13 +45,11 @@
#include "BlockLadder.h"
#include "BlockLeaves.h"
#include "BlockLilypad.h"
-#include "BlockNewLeaves.h"
#include "BlockLever.h"
#include "BlockMelon.h"
#include "BlockMushroom.h"
#include "BlockMycelium.h"
#include "BlockNetherWart.h"
-#include "BlockNote.h"
#include "BlockOre.h"
#include "BlockPiston.h"
#include "BlockPlanks.h"
@@ -251,9 +249,9 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType);
case E_BLOCK_NETHER_WART: return new cBlockNetherWartHandler (a_BlockType);
case E_BLOCK_NETHER_QUARTZ_ORE: return new cBlockOreHandler (a_BlockType);
- case E_BLOCK_NEW_LEAVES: return new cBlockNewLeavesHandler (a_BlockType);
+ case E_BLOCK_NEW_LEAVES: return new cBlockLeavesHandler (a_BlockType);
case E_BLOCK_NEW_LOG: return new cBlockSidewaysHandler (a_BlockType);
- case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType);
+ case E_BLOCK_NOTE_BLOCK: return new cBlockEntityHandler (a_BlockType);
case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType);
case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler;
case E_BLOCK_PLANKS: return new cBlockPlanksHandler (a_BlockType);
diff --git a/src/Blocks/BlockMelon.h b/src/Blocks/BlockMelon.h
index 2f7d9a461..60202d66e 100644
--- a/src/Blocks/BlockMelon.h
+++ b/src/Blocks/BlockMelon.h
@@ -19,8 +19,8 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- MTRand r1;
- a_Pickups.push_back(cItem(E_ITEM_MELON_SLICE, (char)(3 + r1.randInt(4)), 0));
+ cFastRandom Random;
+ a_Pickups.push_back(cItem(E_ITEM_MELON_SLICE, (char)(3 + Random.NextInt(5)), 0));
}
diff --git a/src/Blocks/BlockNewLeaves.h b/src/Blocks/BlockNewLeaves.h
deleted file mode 100644
index 5a267e8c6..000000000
--- a/src/Blocks/BlockNewLeaves.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#pragma once
-#include "BlockHandler.h"
-#include "BlockLeaves.h"
-#include "../World.h"
-
-
-
-
-
-
-class cBlockNewLeavesHandler :
- public cBlockLeavesHandler
-{
-public:
- cBlockNewLeavesHandler(BLOCKTYPE a_BlockType)
- : cBlockLeavesHandler(a_BlockType)
- {
- }
-
-
- virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
- {
- MTRand rand;
-
- // Only the first 2 bits contain the display information, the others are for growing
- if (rand.randInt(5) == 0)
- {
- a_Pickups.push_back(cItem(E_BLOCK_SAPLING, 1, (a_BlockMeta & 3) + 4));
- }
- }
-
-
- void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override
- {
- cBlockHandler::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ);
- }
-} ;
-
-
-
-
-
diff --git a/src/Blocks/BlockNote.h b/src/Blocks/BlockNote.h
deleted file mode 100644
index fef38d845..000000000
--- a/src/Blocks/BlockNote.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-#include "BlockHandler.h"
-#include "BlockEntity.h"
-
-class cBlockNoteHandler : public cBlockEntityHandler
-{
-public:
- cBlockNoteHandler(BLOCKTYPE a_BlockType)
- : cBlockEntityHandler(a_BlockType)
- {
- }
-
-};
diff --git a/src/Blocks/BlockOre.h b/src/Blocks/BlockOre.h
index 9684dbb19..0067d475f 100644
--- a/src/Blocks/BlockOre.h
+++ b/src/Blocks/BlockOre.h
@@ -2,7 +2,6 @@
#pragma once
#include "BlockHandler.h"
-#include "../MersenneTwister.h"
#include "../World.h"
@@ -20,58 +19,41 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- short ItemType = m_BlockType;
- char Count = 1;
- short Meta = 0;
-
- MTRand r1;
+ cFastRandom Random;
+
switch (m_BlockType)
{
case E_BLOCK_LAPIS_ORE:
{
- ItemType = E_ITEM_DYE;
- Count = 4 + (char)r1.randInt(4);
- Meta = 4;
+ a_Pickups.push_back(cItem(E_ITEM_DYE, (char)(4 + Random.NextInt(5)), 4));
break;
}
case E_BLOCK_REDSTONE_ORE:
case E_BLOCK_REDSTONE_ORE_GLOWING:
{
- Count = 4 + (char)r1.randInt(1);
+ a_Pickups.push_back(cItem(E_ITEM_REDSTONE_DUST, (char)(4 + Random.NextInt(2)), 0));
break;
}
- default:
- {
- Count = 1;
- break;
- }
- }
-
- switch (m_BlockType)
- {
case E_BLOCK_DIAMOND_ORE:
{
- ItemType = E_ITEM_DIAMOND;
- break;
- }
- case E_BLOCK_REDSTONE_ORE:
- case E_BLOCK_REDSTONE_ORE_GLOWING:
- {
- ItemType = E_ITEM_REDSTONE_DUST;
+ a_Pickups.push_back(cItem(E_ITEM_DIAMOND));
break;
}
case E_BLOCK_EMERALD_ORE:
{
- ItemType = E_ITEM_EMERALD;
+ a_Pickups.push_back(cItem(E_ITEM_EMERALD));
break;
}
case E_BLOCK_COAL_ORE:
{
- ItemType = E_ITEM_COAL;
+ a_Pickups.push_back(cItem(E_ITEM_COAL));
break;
}
+ default:
+ {
+ ASSERT(!"Unhandled ore!");
+ }
}
- a_Pickups.push_back(cItem(ItemType, Count, Meta));
}
} ;
diff --git a/src/Blocks/BlockPlanks.h b/src/Blocks/BlockPlanks.h
index de84ed319..4c5bb4860 100644
--- a/src/Blocks/BlockPlanks.h
+++ b/src/Blocks/BlockPlanks.h
@@ -24,8 +24,7 @@ public:
) override
{
a_BlockType = m_BlockType;
- NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage);
- a_BlockMeta = Meta;
+ a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage);
return true;
}
diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h
index fc74e89d0..8fac2a126 100644
--- a/src/Blocks/BlockPortal.h
+++ b/src/Blocks/BlockPortal.h
@@ -36,7 +36,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return; // No pickups
+ // No pickups
}
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
@@ -47,15 +47,15 @@ public:
return;
}
- int PosX = a_Chunk.GetPosX() * 16 + a_RelX;
- int PosZ = a_Chunk.GetPosZ() * 16 + a_RelZ;
+ int PosX = a_Chunk.GetPosX() * cChunkDef::Width + a_RelX;
+ int PosZ = a_Chunk.GetPosZ() * cChunkDef::Width + a_RelZ;
a_WorldInterface.SpawnMob(PosX, a_RelY, PosZ, cMonster::mtZombiePigman);
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
- if ((a_RelY - 1 < 0) || (a_RelY + 1 > cChunkDef::Height))
+ if ((a_RelY <= 0) || (a_RelY >= cChunkDef::Height))
{
return false; // In case someone places a portal with meta 1 or 2 at boundaries, and server tries to get invalid coords at Y - 1 or Y + 1
}
diff --git a/src/Blocks/BlockPressurePlate.h b/src/Blocks/BlockPressurePlate.h
index adec36eb6..a5c34a776 100644
--- a/src/Blocks/BlockPressurePlate.h
+++ b/src/Blocks/BlockPressurePlate.h
@@ -17,7 +17,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- // Reset meta to 0
+ // Reset meta to zero
a_Pickups.push_back(cItem(m_BlockType, 1, 0));
}
@@ -29,7 +29,7 @@ public:
}
BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
- return ((BlockBelow == E_BLOCK_FENCE_GATE) || (BlockBelow == E_BLOCK_FENCE) || cBlockInfo::IsSolid(BlockBelow));
+ return (cBlockInfo::IsSolid(BlockBelow));
}
} ;
diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h
index 2ce7e71e4..edc4fb9c5 100644
--- a/src/Blocks/BlockQuartz.h
+++ b/src/Blocks/BlockQuartz.h
@@ -25,6 +25,7 @@ public:
{
a_BlockType = m_BlockType;
NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage);
+
if (Meta != E_META_QUARTZ_PILLAR) // Check if the block is a pillar block.
{
a_BlockMeta = Meta;
diff --git a/src/Blocks/BlockRedstone.h b/src/Blocks/BlockRedstone.h
index a898c9acb..37d61ed73 100644
--- a/src/Blocks/BlockRedstone.h
+++ b/src/Blocks/BlockRedstone.h
@@ -26,8 +26,8 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- // Reset meta to 0
- a_Pickups.push_back(cItem(E_ITEM_REDSTONE_DUST, 1));
+ // Reset meta to zero
+ a_Pickups.push_back(cItem(E_ITEM_REDSTONE_DUST, 1, 0));
}
} ;
diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h
index 4c8a6a087..4b18add12 100644
--- a/src/Blocks/BlockRedstoneRepeater.h
+++ b/src/Blocks/BlockRedstoneRepeater.h
@@ -23,7 +23,7 @@ public:
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
int a_CursorX, int a_CursorY, int a_CursorZ,
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
- ) override
+ ) override
{
a_BlockType = m_BlockType;
a_BlockMeta = RepeaterRotationToMetaData(a_Player->GetYaw());
@@ -46,7 +46,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- // Reset meta to 0
+ // Reset meta to zero
a_Pickups.push_back(cItem(E_ITEM_REDSTONE_REPEATER, 1, 0));
}
@@ -59,7 +59,7 @@ public:
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
- return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
+ return ((a_RelY > 0) && cBlockInfo::IsSolid(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)));
}
diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h
index a7ccf1714..417969a82 100644
--- a/src/Blocks/BlockStairs.h
+++ b/src/Blocks/BlockStairs.h
@@ -16,8 +16,8 @@ public:
{
}
-
-
+
+
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@@ -53,8 +53,8 @@ public:
}
return true;
}
-
-
+
+
virtual const char * GetStepSound(void) override
{
if (
@@ -64,7 +64,7 @@ public:
(m_BlockType == E_BLOCK_ACACIA_WOOD_STAIRS) ||
(m_BlockType == E_BLOCK_BIRCH_WOOD_STAIRS) ||
(m_BlockType == E_BLOCK_DARK_OAK_WOOD_STAIRS)
- )
+ )
{
return "step.wood";
}
@@ -72,17 +72,20 @@ public:
return "step.stone";
}
+
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- // Reset meta to 0
+ // Reset meta to zero
a_Pickups.push_back(cItem(m_BlockType, 1, 0));
}
+
virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta) override
{
return true;
}
-
+
+
static NIBBLETYPE RotationToMetaData(double a_Rotation)
{
a_Rotation += 90 + 45; // So its not aligned with axis
@@ -108,14 +111,11 @@ public:
}
}
-
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
{
// Toggle bit 3:
return (a_Meta & 0x0b) | ((~a_Meta) & 0x04);
}
-
-
} ;
diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h
index 84d3b2e7d..5902c791b 100644
--- a/src/Blocks/BlockSugarcane.h
+++ b/src/Blocks/BlockSugarcane.h
@@ -29,6 +29,7 @@ public:
{
return false;
}
+
switch (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ))
{
case E_BLOCK_DIRT:
diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h
index c73118870..df5574d5d 100644
--- a/src/Blocks/BlockTorch.h
+++ b/src/Blocks/BlockTorch.h
@@ -126,7 +126,7 @@ public:
(BlockInQuestion == E_BLOCK_NETHER_BRICK_FENCE) ||
(BlockInQuestion == E_BLOCK_COBBLESTONE_WALL)) &&
(Face == BLOCK_FACE_TOP)
- )
+ )
{
return Face;
}
@@ -162,7 +162,7 @@ public:
(BlockInQuestion == E_BLOCK_END_PORTAL_FRAME) || // Actual vanilla behaviour
(BlockInQuestion == E_BLOCK_NETHER_BRICK_FENCE) ||
(BlockInQuestion == E_BLOCK_COBBLESTONE_WALL)
- )
+ )
{
// Torches can be placed on tops of glass and fences, despite them being 'untorcheable'
// No need to check for upright orientation, it was done when the torch was placed
diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h
index 6a36ab874..a6327b5c2 100644
--- a/src/Blocks/BlockTrapdoor.h
+++ b/src/Blocks/BlockTrapdoor.h
@@ -23,7 +23,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- // Reset meta to 0
+ // Reset meta to zero
a_Pickups.push_back(cItem(m_BlockType, 1, 0));
}
@@ -53,7 +53,7 @@ public:
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
int a_CursorX, int a_CursorY, int a_CursorZ,
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
- ) override
+ ) override
{
a_BlockType = m_BlockType;
a_BlockMeta = BlockFaceToMetaData(a_BlockFace);
@@ -103,9 +103,10 @@ public:
a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta);
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true);
- BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
+ BLOCKTYPE BlockIsOn;
+ a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
- return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn);
+ return ((a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn));
}
};
diff --git a/src/Blocks/BlockTripwireHook.h b/src/Blocks/BlockTripwireHook.h
index f849fb8ad..4f9d79483 100644
--- a/src/Blocks/BlockTripwireHook.h
+++ b/src/Blocks/BlockTripwireHook.h
@@ -21,10 +21,9 @@ public:
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
int a_CursorX, int a_CursorY, int a_CursorZ,
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
- ) override
+ ) override
{
a_BlockType = m_BlockType;
-
a_BlockMeta = DirectionToMetadata(a_BlockFace);
return true;
@@ -56,7 +55,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- // Reset meta to 0
+ // Reset meta to zero
a_Pickups.push_back(cItem(E_BLOCK_TRIPWIRE_HOOK, 1, 0));
}
@@ -66,9 +65,10 @@ public:
a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta);
AddFaceDirection(a_RelX, a_RelY, a_RelZ, MetadataToDirection(Meta), true);
- BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
+ BLOCKTYPE BlockIsOn;
+ a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
- return (a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(BlockIsOn);
+ return ((a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(BlockIsOn));
}
virtual const char * GetStepSound(void) override
diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h
index 1e1f6d8d2..578224c61 100644
--- a/src/Blocks/BlockVine.h
+++ b/src/Blocks/BlockVine.h
@@ -46,7 +46,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- // Reset meta to 0
+ // Reset meta to zero
a_Pickups.push_back(cItem(E_BLOCK_VINES, 1, 0));
}
@@ -80,7 +80,7 @@ public:
/// Returns true if the specified block type is good for vines to attach to
static bool IsBlockAttachable(BLOCKTYPE a_BlockType)
{
- return (a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES) || cBlockInfo::IsSolid(a_BlockType);
+ return ((a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES) || cBlockInfo::IsSolid(a_BlockType));
}
@@ -182,7 +182,7 @@ public:
a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, Block);
if (Block == E_BLOCK_AIR)
{
- if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, a_RelX * cChunkDef::Width, a_RelY - 1, a_RelZ * cChunkDef::Width, ssVineSpread))
+ if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY - 1, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, ssVineSpread))
{
a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
}
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 7bdf4196d..116c0f3a0 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -1,3 +1,4 @@
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#ifndef _WIN32
diff --git a/src/Items/ItemGoldenApple.h b/src/Items/ItemGoldenApple.h
index 4e1096e65..02ac0202c 100644
--- a/src/Items/ItemGoldenApple.h
+++ b/src/Items/ItemGoldenApple.h
@@ -29,7 +29,7 @@ public:
a_Player->AddEntityEffect(cEntityEffect::effRegeneration, 100, 1);
// When the apple is a 'notch apple', give extra effects:
- if (a_Item->m_ItemDamage > 0)
+ if (a_Item->m_ItemDamage >= E_META_GOLDEN_APPLE_ENCHANTED)
{
a_Player->AddEntityEffect(cEntityEffect::effRegeneration, 600, 4);
a_Player->AddEntityEffect(cEntityEffect::effResistance, 6000, 0);
diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h
index 7d5760fa9..cd235678d 100644
--- a/src/Items/ItemShovel.h
+++ b/src/Items/ItemShovel.h
@@ -19,7 +19,6 @@ public:
cItemShovelHandler(int a_ItemType)
: cItemHandler(a_ItemType)
{
-
}
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
diff --git a/src/World.cpp b/src/World.cpp
index b357b8a23..2027e215a 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1,3 +1,4 @@
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "BlockID.h"
From 67fc19301e4909101c6f2f31cb5d49413fe47d42 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 20 Aug 2014 12:14:56 +0200
Subject: [PATCH 28/28] Removed old classes from the CMakeLists.txt
---
src/Blocks/CMakeLists.txt | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt
index 05b7bfab4..9f971a8bd 100644
--- a/src/Blocks/CMakeLists.txt
+++ b/src/Blocks/CMakeLists.txt
@@ -57,8 +57,6 @@ SET (HDRS
BlockMushroom.h
BlockMycelium.h
BlockNetherWart.h
- BlockNewLeaves.h
- BlockNote.h
BlockOre.h
BlockPiston.h
BlockPlanks.h