From 4271d719b68521f91770574b3064525512116670 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 7 Aug 2014 01:07:32 +0200 Subject: Added SetDoDaylightCycle() and IsDaylightCycleEnabled() to cWorld. I need this for a GameRule plugin. --- src/ClientHandle.cpp | 11 ++++++++++- src/ClientHandle.h | 2 +- src/World.cpp | 49 ++++++++++++++++++++++++++++++++----------------- src/World.h | 14 +++++++++++++- 4 files changed, 56 insertions(+), 20 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; + m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0); - // Wrap time of day each 20 minutes (1200 seconds) - if (m_TimeOfDaySecs > 1200.0) + if (m_DoDaylightCycle) { - m_TimeOfDaySecs -= 1200.0; - } + // 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; - m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0); - m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0); + // Wrap time of day each 20 minutes (1200 seconds) + if (m_TimeOfDaySecs > 1200.0) + { + m_TimeOfDaySecs -= 1200.0; + } - // Updates the sky darkness based on current time of day - UpdateSkyDarkness(); + m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0); - // Broadcast time update every 40 ticks (2 seconds) - if (m_LastTimeUpdate < m_WorldAge - 40) - { - BroadcastTimeUpdate(); - m_LastTimeUpdate = m_WorldAge; + // 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 -- cgit v1.2.3 From 32e1e9a5536f92d074d51cca207f21c372973629 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 8 Aug 2014 18:38:20 +0200 Subject: 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 -- cgit v1.2.3 From cccc321384be18d4ac75e83abf3ce4d19a2a3d56 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 10 Aug 2014 16:46:03 +0200 Subject: 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 -- cgit v1.2.3 From f90078c09ff576d3f8af1554872c53afbdcd6fe0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 10 Aug 2014 16:48:20 +0200 Subject: 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); -- cgit v1.2.3 From 42bad0edec58f42e4072360c52870d3be9ced3c5 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 10 Aug 2014 20:06:03 +0200 Subject: 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); -- cgit v1.2.3 From 47c928cab7d1ff73e50925bc7ef50586b6ec9821 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 11 Aug 2014 00:20:28 +0200 Subject: 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); } } -- cgit v1.2.3 From 60ea4bb937ba56c6dcaf57dda377beed972cf0a5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 13 Aug 2014 11:56:47 +0100 Subject: 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); -- cgit v1.2.3 From 2321d2af41e935d8353b18592c29d58c766a5658 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 13 Aug 2014 12:01:13 +0100 Subject: 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; -- cgit v1.2.3 From 008c1cdaf436dec2d7a4a925c6a600570594d6a2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 14 Aug 2014 01:03:30 +0200 Subject: 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); -- cgit v1.2.3