From 8c144207dc6bcbc9871c3a577b864f7c3fcd074c Mon Sep 17 00:00:00 2001 From: Scott Moore Date: Wed, 8 Apr 2015 00:41:19 +1000 Subject: Implement backend for /title command --- src/ClientHandle.cpp | 63 +++++++++++++++++++++++++++ src/ClientHandle.h | 7 +++ src/Protocol/Protocol.h | 7 +++ src/Protocol/Protocol17x.cpp | 63 +++++++++++++++++++++++++++ src/Protocol/Protocol17x.h | 7 +++ src/Protocol/Protocol18x.cpp | 86 +++++++++++++++++++++++++++++++++++++ src/Protocol/Protocol18x.h | 7 +++ src/Protocol/ProtocolRecognizer.cpp | 70 ++++++++++++++++++++++++++++++ src/Protocol/ProtocolRecognizer.h | 7 +++ 9 files changed, 317 insertions(+) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 28fccb68e..2ce212421 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2320,6 +2320,15 @@ void cClientHandle::SendHealth(void) +void cClientHandle::SendHideTitle(void) +{ + m_Protocol->SendHideTitle(); +} + + + + + void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item); @@ -2514,6 +2523,15 @@ void cClientHandle::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effec +void cClientHandle::SendResetTitle() +{ + m_Protocol->SendResetTitle(); +} + + + + + void cClientHandle::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { m_Protocol->SendRespawn(a_Dimension, a_ShouldIgnoreDimensionChecks); @@ -2568,6 +2586,42 @@ void cClientHandle::SendDisplayObjective(const AString & a_Objective, cScoreboar +void cClientHandle::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + m_Protocol->SendSetSubTitle(a_SubTitle); +} + + + + + +void cClientHandle::SendSetRawSubTitle(const AString & a_SubTitle) +{ + m_Protocol->SendSetRawSubTitle(a_SubTitle); +} + + + + + +void cClientHandle::SendSetTitle(const cCompositeChat & a_Title) +{ + m_Protocol->SendSetTitle(a_Title); +} + + + + + +void cClientHandle::SendSetRawTitle(const AString & a_Title) +{ + m_Protocol->SendSetRawTitle(a_Title); +} + + + + + void cClientHandle::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { m_Protocol->SendSoundEffect(a_SoundName, a_X, a_Y, a_Z, a_Volume, a_Pitch); @@ -2658,6 +2712,15 @@ void cClientHandle::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cClientHandle::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + m_Protocol->SendTitleTimes(a_FadeInTicks, a_DisplayTicks, a_FadeOutTicks); +} + + + + + void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay, a_DoDaylightCycle); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 9e5287985..e004c3bfb 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -171,6 +171,7 @@ public: // tolua_export void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion); void SendGameMode (eGameMode a_GameMode); void SendHealth (void); + void SendHideTitle (void); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale); void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale); @@ -190,9 +191,14 @@ public: // tolua_export void SendPlayerSpawn (const cPlayer & a_Player); void SendPluginMessage (const AString & a_Channel, const AString & a_Message); // Exported in ManualBindings.cpp void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID); + void SendResetTitle (void); void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks = false); void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode); void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); + void SendSetSubTitle (const cCompositeChat & a_SubTitle); + void SendSetRawSubTitle (const AString & a_SubTitle); + void SendSetTitle (const cCompositeChat & a_Title); + void SendSetRawTitle (const AString & a_Title); void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch); // tolua_export void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data); void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock); @@ -203,6 +209,7 @@ public: // tolua_export void SendTabCompletionResults (const AStringVector & a_Results); void SendTeleportEntity (const cEntity & a_Entity); void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ); + void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks); 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); diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index d8399049e..95adc23e9 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -86,6 +86,7 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0; virtual void SendGameMode (eGameMode a_GameMode) = 0; virtual void SendHealth (void) = 0; + virtual void SendHideTitle (void) = 0; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; @@ -109,12 +110,17 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) = 0; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) = 0; + virtual void SendResetTitle (void) = 0; virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) = 0; virtual void SendExperience (void) = 0; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) = 0; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) = 0; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) = 0; virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) = 0; + virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) = 0; + virtual void SendSetRawSubTitle (const AString & a_SubTitle) = 0; + virtual void SendSetTitle (const cCompositeChat & a_Title) = 0; + virtual void SendSetRawTitle (const AString & a_Title) = 0; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) = 0; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0; @@ -125,6 +131,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 SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) = 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; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 2bc58e7e5..e1e48e43f 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -555,6 +555,15 @@ void cProtocol172::SendHealth(void) +void cProtocol172::SendHideTitle(void) +{ + // Not implemented in this protocol version +} + + + + + void cProtocol172::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { ASSERT(m_State == 3); // In game mode? @@ -985,6 +994,15 @@ void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect +void cProtocol172::SendResetTitle(void) +{ + // Not implemented in this protocol version +} + + + + + void cProtocol172::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks) @@ -1084,6 +1102,42 @@ void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard +void cProtocol172::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + // Not implemented in this protocol version +} + + + + + +void cProtocol172::SendSetRawSubTitle(const AString & a_SubTitle) +{ + // Not implemented in this protocol version +} + + + + + +void cProtocol172::SendSetTitle(const cCompositeChat & a_Title) +{ + // Not implemented in this protocol version +} + + + + + +void cProtocol172::SendSetRawTitle(const AString & a_Title) +{ + // Not implemented in this protocol version +} + + + + + void cProtocol172::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { ASSERT(m_State == 3); // In game mode? @@ -1286,6 +1340,15 @@ void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cProtocol172::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + // Not implemented in this protocol version +} + + + + + void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_State == 3); // In game mode? diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 1212cc325..553856eaa 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -90,6 +90,7 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; + virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; @@ -112,9 +113,14 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; + virtual void SendResetTitle (void) override; virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; + virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) override; + virtual void SendSetRawSubTitle (const AString & a_SubTitle) override; + virtual void SendSetTitle (const cCompositeChat & a_Title) override; + virtual void SendSetRawTitle (const AString & a_Title) override; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; @@ -125,6 +131,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 SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) 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; diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index a1ca25200..20b55f461 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -542,6 +542,18 @@ void cProtocol180::SendHealth(void) +void cProtocol180::SendHideTitle(void) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(3); // Hide title +} + + + + + void cProtocol180::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { ASSERT(m_State == 3); // In game mode? @@ -1021,6 +1033,18 @@ void cProtocol180::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect +void cProtocol180::SendResetTitle(void) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(4); // Reset title +} + + + + + void cProtocol180::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks) @@ -1123,6 +1147,52 @@ void cProtocol180::SendDisplayObjective(const AString & a_Objective, cScoreboard +void cProtocol180::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + SendSetRawSubTitle(a_SubTitle.CreateJsonString(false)); +} + + + + + +void cProtocol180::SendSetRawSubTitle(const AString & a_SubTitle) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(1); // Set subtitle + + Pkt.WriteString(a_SubTitle); +} + + + + + +void cProtocol180::SendSetTitle(const cCompositeChat & a_Title) +{ + SendSetRawTitle(a_Title.CreateJsonString(false)); +} + + + + + +void cProtocol180::SendSetRawTitle(const AString & a_Title) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(0); // Set title + + Pkt.WriteString(a_Title); +} + + + + + void cProtocol180::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { ASSERT(m_State == 3); // In game mode? @@ -1330,6 +1400,22 @@ void cProtocol180::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cProtocol180::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(2); // Set title display times + + Pkt.WriteBEInt32(a_FadeInTicks); + Pkt.WriteBEInt32(a_DisplayTicks); + Pkt.WriteBEInt32(a_FadeOutTicks); +} + + + + + void cProtocol180::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_State == 3); // In game mode? diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h index 9aa5ed827..06a57b216 100644 --- a/src/Protocol/Protocol18x.h +++ b/src/Protocol/Protocol18x.h @@ -85,6 +85,7 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; + virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; @@ -108,6 +109,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; + virtual void SendResetTitle (void) override; virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override; virtual void SendExperience (void) override; @@ -115,6 +117,10 @@ public: virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override; + virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) override; + virtual void SendSetRawSubTitle (const AString & a_SubTitle) override; + virtual void SendSetTitle (const cCompositeChat & a_Title) override; + virtual void SendSetRawTitle (const AString & a_Title) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; @@ -124,6 +130,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 SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) 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; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 36f8bc791..6c599dedc 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -350,6 +350,16 @@ void cProtocolRecognizer::SendHealth(void) +void cProtocolRecognizer::SendHideTitle(void) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendHideTitle(); +} + + + + + void cProtocolRecognizer::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) { ASSERT(m_Protocol != nullptr); @@ -588,6 +598,16 @@ void cProtocolRecognizer::SendRemoveEntityEffect(const cEntity & a_Entity, int a +void cProtocolRecognizer::SendResetTitle(void) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendResetTitle(); +} + + + + + void cProtocolRecognizer::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { ASSERT(m_Protocol != nullptr); @@ -648,6 +668,46 @@ void cProtocolRecognizer::SendDisplayObjective(const AString & a_Objective, cSco +void cProtocolRecognizer::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendSetSubTitle(a_SubTitle); +} + + + + + +void cProtocolRecognizer::SendSetRawSubTitle(const AString & a_SubTitle) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendSetRawSubTitle(a_SubTitle); +} + + + + + +void cProtocolRecognizer::SendSetTitle(const cCompositeChat & a_Title) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendSetTitle(a_Title); +} + + + + + +void cProtocolRecognizer::SendSetRawTitle(const AString & a_Title) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendSetRawTitle(a_Title); +} + + + + + void cProtocolRecognizer::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { ASSERT(m_Protocol != nullptr); @@ -748,6 +808,16 @@ void cProtocolRecognizer::SendThunderbolt(int a_BlockX, int a_BlockY, int a_Bloc +void cProtocolRecognizer::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendTitleTimes(a_FadeInTicks, a_DisplayTicks, a_FadeOutTicks); +} + + + + + void cProtocolRecognizer::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_Protocol != nullptr); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index d46d31cb1..8454549e3 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -73,6 +73,7 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; + virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; @@ -96,12 +97,17 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; + virtual void SendResetTitle (void) override; virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override; + virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) override; + virtual void SendSetRawSubTitle (const AString & a_SubTitle) override; + virtual void SendSetTitle (const cCompositeChat & a_Title) override; + virtual void SendSetRawTitle (const AString & a_Title) override; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; @@ -112,6 +118,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 SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) 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; -- cgit v1.2.3 From 0dbba305b6b96f81fe5f9b457dfb4f63d4a420c9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 18 May 2015 14:30:16 +0100 Subject: Fixes #2052 --- src/Entities/Pickup.cpp | 1 + src/Inventory.cpp | 30 ++++++++++++++++++++++++++---- src/Inventory.h | 10 ++-------- src/Items/ItemBucket.h | 4 ++-- src/Items/ItemEmptyMap.h | 2 +- src/Items/ItemMushroomSoup.h | 2 +- 6 files changed, 33 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index f2f76dbf9..520765b29 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -228,6 +228,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest) m_Item.m_ItemCount -= NumAdded; m_World->BroadcastCollectEntity(*this, a_Dest); + // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); if (m_Item.m_ItemCount <= 0) diff --git a/src/Inventory.cpp b/src/Inventory.cpp index c595da5b0..f08dd1896 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -98,7 +98,7 @@ int cInventory::HowManyCanFit(const cItem & a_ItemStack, int a_BeginSlotNum, int -int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst) +int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks) { cItem ToAdd(a_Item); int res = 0; @@ -116,8 +116,30 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT } } - res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1); + for (int SlotIdx = 0; SlotIdx < m_InventorySlots.GetNumSlots(); ++SlotIdx) + { + auto & Slot = m_InventorySlots.GetSlot(SlotIdx); + if (Slot.IsEqual(a_Item)) + { + cItemHandler Handler(Slot.m_ItemType); + int AmountToAdd = std::min(static_cast(Handler.GetMaxStackSize() - Slot.m_ItemCount), ToAdd.m_ItemCount); + res += AmountToAdd; + + cItem SlotAdjusted(Slot); + SlotAdjusted.m_ItemCount += AmountToAdd; + m_InventorySlots.SetSlot(SlotIdx, SlotAdjusted); + + ToAdd.m_ItemCount -= AmountToAdd; + if (ToAdd.m_ItemCount == 0) + { + return res; + } + } + } + + res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks); ToAdd.m_ItemCount = a_Item.m_ItemCount - res; + if (ToAdd.m_ItemCount == 0) { return res; @@ -131,12 +153,12 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT -int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst) +int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks) { int TotalAdded = 0; for (cItems::iterator itr = a_ItemStackList.begin(); itr != a_ItemStackList.end();) { - int NumAdded = AddItem(*itr, a_AllowNewStacks, a_tryToFillEquippedFirst); + int NumAdded = AddItem(*itr, a_AllowNewStacks); if (itr->m_ItemCount == NumAdded) { itr = a_ItemStackList.erase(itr); diff --git a/src/Inventory.h b/src/Inventory.h index b2a8f658b..5501399bd 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -70,23 +70,17 @@ public: /** Adds as many items out of a_ItemStack as can fit. If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. - If a_tryToFillEquippedFirst is set to true, the currently equipped slot will be used first (if empty or - compatible with added items) - if a_tryToFillEquippedFirst is set to false, the regular order applies. Returns the number of items that fit. */ - int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true, bool a_tryToFillEquippedFirst = false); + int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true); /** Same as AddItem, but works on an entire list of item stacks. The a_ItemStackList is modified to reflect the leftover items. If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. - If a_tryToFillEquippedFirst is set to true, the currently equipped slot will be used first (if empty or - compatible with added items) - if a_tryToFillEquippedFirst is set to false, the regular order applies. Returns the total number of items that fit. */ - int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst); + int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks); /** Removes the specified item from the inventory, as many as possible, up to a_ItemStack.m_ItemCount. Returns the number of items that were removed. */ diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 015720415..47429551a 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -96,7 +96,7 @@ public: ASSERT(!"Inventory bucket mismatch"); return true; } - if (a_Player->GetInventory().AddItem(cItem(NewItem), true, true) != 1) + if (a_Player->GetInventory().AddItem(cItem(NewItem)) != 1) { // The bucket didn't fit, toss it as a pickup: a_Player->TossPickup(cItem(NewItem)); @@ -137,7 +137,7 @@ public: return false; } cItem Item(E_ITEM_BUCKET, 1); - if (!a_Player->GetInventory().AddItem(Item, true, true)) + if (!a_Player->GetInventory().AddItem(Item)) { return false; } diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 6e944b4da..fba8c0a2c 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -60,7 +60,7 @@ public: return true; } - a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff)), true, true); + a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff))); return true; } diff --git a/src/Items/ItemMushroomSoup.h b/src/Items/ItemMushroomSoup.h index dba313ec5..1a761cbf1 100644 --- a/src/Items/ItemMushroomSoup.h +++ b/src/Items/ItemMushroomSoup.h @@ -41,7 +41,7 @@ public: // Return a bowl to the inventory if (!a_Player->IsGameModeCreative()) { - a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL), true, true); + a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL)); } return true; } -- cgit v1.2.3 From 1632d5f8f1f3f1edb7ac2d0f4c79be9fbdae91ca Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 18 May 2015 15:43:24 +0100 Subject: Fixes #2003 --- src/UI/SlotArea.cpp | 2 +- src/UI/Window.cpp | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 37683a8e5..accd44b06 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1394,7 +1394,7 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) // cSlotAreaEnchanting: cSlotAreaEnchanting::cSlotAreaEnchanting(cWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ) : - cSlotAreaTemporary(1, a_ParentWindow), + cSlotAreaTemporary(2, a_ParentWindow), m_BlockX(a_BlockX), m_BlockY(a_BlockY), m_BlockZ(a_BlockZ) diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index d1c08acec..61e25651b 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -92,9 +92,9 @@ const AString cWindow::GetWindowTypeName(void) const int cWindow::GetNumSlots(void) const { int res = 0; - for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) + for (const auto & itr : m_SlotAreas) { - res += (*itr)->GetNumSlots(); + res += itr->GetNumSlots(); } // for itr - m_SlotAreas[] return res; } @@ -261,16 +261,14 @@ void cWindow::Clicked( } int LocalSlotNum = a_SlotNum; - int idx = 0; - for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) + for (const auto & itr : m_SlotAreas) { - if (LocalSlotNum < (*itr)->GetNumSlots()) + if (LocalSlotNum < itr->GetNumSlots()) { - (*itr)->Clicked(a_Player, LocalSlotNum, a_ClickAction, a_ClickedItem); + itr->Clicked(a_Player, LocalSlotNum, a_ClickAction, a_ClickedItem); return; } - LocalSlotNum -= (*itr)->GetNumSlots(); - idx++; + LocalSlotNum -= itr->GetNumSlots(); } LOGWARNING("Slot number higher than available window slots: %d, max %d received from \"%s\"; ignoring.", -- cgit v1.2.3 From 10c9e66aad9a0d994c5c227f5dedec4af19db9b2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 24 May 2015 13:37:36 +0100 Subject: Fixes #2041 --- src/UI/SlotArea.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index accd44b06..5b58b18b6 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -2154,10 +2154,10 @@ bool cSlotAreaArmor::CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item) { switch (a_SlotNum) { - case 0: return ItemCategory::IsHelmet (a_Item.m_ItemType); + case 0: return (ItemCategory::IsHelmet(a_Item.m_ItemType) || (a_Item.m_ItemType == E_BLOCK_PUMPKIN)); case 1: return ItemCategory::IsChestPlate(a_Item.m_ItemType); - case 2: return ItemCategory::IsLeggings (a_Item.m_ItemType); - case 3: return ItemCategory::IsBoots (a_Item.m_ItemType); + case 2: return ItemCategory::IsLeggings(a_Item.m_ItemType); + case 3: return ItemCategory::IsBoots(a_Item.m_ItemType); } return false; } -- cgit v1.2.3 From 5049fd0fbf2fe2e54d86d9d0f704d5daa301f819 Mon Sep 17 00:00:00 2001 From: linnemannr Date: Sun, 24 May 2015 20:07:31 -0600 Subject: Support building on FreeBSD SetFlags.cmake Add -lexecinfo to linker flags for FreeBSD to resolve backtrace() lib/sqlite/CMakeLists.txt Define _XOPEN_SOURCE to 600 instead of __POSIX_VISIBLE to 200112 for POSIX 1-2001 support. For POSIX standards, the _XOPEN_SOURCE define controls the eventual value of __POSIX_VISIBLE. _XOPEN_SOURCE is defined to 500 in sqlite.c if not already defined, which sets up _POSIX_C_SOURCE and __POSIX_VISIBLE to the 199506 for POSIX.1c lib/tolua++/CMakeLists.txt src/CMakeLists.txt Add /usr/local/lib to the library search path for FreeBSD builds src/OSSupport/Errors.cpp Correct the strerror_r() implementation determination to check whether _GNU_SOURCE is defined, not what it evaluates to --- src/CMakeLists.txt | 5 +++++ src/OSSupport/Errors.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25de24c91..1b721100d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -332,4 +332,9 @@ endif () if (WIN32) target_link_libraries(${EXECUTABLE} expat tolualib ws2_32.lib Psapi.lib) endif() + +if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + add_flags_lnk(-L/usr/local/lib) +endif() + target_link_libraries(${EXECUTABLE} luaexpat jsoncpp mbedtls zlib sqlite lua SQLiteCpp event_core event_extra) diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp index a5361e1a6..407799495 100644 --- a/src/OSSupport/Errors.cpp +++ b/src/OSSupport/Errors.cpp @@ -22,7 +22,7 @@ AString GetOSErrorString( int a_ErrNo) // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - #if !defined(__APPLE__) && ( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r() + #if !defined(__APPLE__) && defined( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r() char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer)); if (res != nullptr) -- cgit v1.2.3 From 6735b0d5346ba17d282bb27ca00f92e6d963a516 Mon Sep 17 00:00:00 2001 From: worktycho Date: Mon, 25 May 2015 18:43:18 +0100 Subject: Only add default plugins if there are not any plugins Fixes #2082 --- src/Bindings/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 4dc3e20d3..5b6bec728 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1935,7 +1935,7 @@ size_t cPluginManager::GetNumLoadedPlugins(void) const AStringVector cPluginManager::GetFoldersToLoad(cSettingsRepositoryInterface & a_Settings) { // Check if the Plugins section exists. - if (a_Settings.KeyExists("Plugins")) + if (!a_Settings.KeyExists("Plugins")) { InsertDefaultPlugins(a_Settings); } -- cgit v1.2.3 From c3b872ad933a720c94886e0d614154d10a781dd1 Mon Sep 17 00:00:00 2001 From: Lukas Pioch Date: Tue, 26 May 2015 05:36:46 +0200 Subject: Added method to get the uptime of the server in seconds. Implements #1650. --- src/Root.cpp | 32 ++++++++++++++-------------- src/Root.h | 69 ++++++++++++++++++++++++++++++++---------------------------- 2 files changed, 53 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/Root.cpp b/src/Root.cpp index c3c880e73..b28e7c894 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -72,7 +72,7 @@ cRoot::~cRoot() void cRoot::InputThread(cRoot & a_Params) { cLogCommandOutputCallback Output; - + while (!cRoot::m_ShouldStop && !a_Params.m_bRestart && !m_TerminateEventRaised && std::cin.good()) { AString Command; @@ -105,12 +105,12 @@ void cRoot::Start(std::unique_ptr overridesRepo) 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 - + cLogger::cListener * consoleLogListener = MakeConsoleListener(); cLogger::cListener * fileLogListener = new cFileListener(); cLogger::GetInstance().AttachListener(consoleLogListener); cLogger::GetInstance().AttachListener(fileLogListener); - + LOG("--- Started Log ---\n"); #ifdef BUILD_ID @@ -162,30 +162,30 @@ void cRoot::Start(std::unique_ptr overridesRepo) m_RankManager->Initialize(*m_MojangAPI); m_CraftingRecipes = new cCraftingRecipes; m_FurnaceRecipe = new cFurnaceRecipe(); - + LOGD("Loading worlds..."); LoadWorlds(*settingsRepo); LOGD("Loading plugin manager..."); m_PluginManager = new cPluginManager(); m_PluginManager->ReloadPluginsNow(*settingsRepo); - + LOGD("Loading MonsterConfig..."); m_MonsterConfig = new cMonsterConfig; // This sets stuff in motion LOGD("Starting Authenticator..."); m_Authenticator.Start(*settingsRepo); - + LOGD("Starting worlds..."); StartWorlds(); - + if (settingsRepo->GetValueSetB("DeadlockDetect", "Enabled", true)) { LOGD("Starting deadlock detector..."); dd.Start(settingsRepo->GetValueSetI("DeadlockDetect", "IntervalSec", 20)); } - + settingsRepo->Flush(); LOGD("Finalising startup..."); @@ -207,6 +207,10 @@ void cRoot::Start(std::unique_ptr overridesRepo) #endif LOG("Startup complete, took %ldms!", static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - BeginTime).count())); + + // Save the current time + m_StartTime = std::chrono::steady_clock::now(); + #ifdef _WIN32 EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button #endif @@ -253,7 +257,7 @@ void cRoot::Start(std::unique_ptr overridesRepo) LOGD("Unloading worlds..."); UnloadWorlds(); - + LOGD("Stopping plugin manager..."); delete m_PluginManager; m_PluginManager = nullptr; @@ -264,9 +268,9 @@ void cRoot::Start(std::unique_ptr overridesRepo) LOG("Shutdown successful!"); } - + LOG("--- Stopped Log ---"); - + cLogger::GetInstance().DetachListener(consoleLogListener); delete consoleLogListener; cLogger::GetInstance().DetachListener(fileLogListener); @@ -299,7 +303,7 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings) { return; } - + bool FoundAdditionalWorlds = false; for (auto WorldNameValue : Worlds) { @@ -850,7 +854,3 @@ int cRoot::GetFurnaceFuelBurnTime(const cItem & a_Fuel) cFurnaceRecipe * FR = Get()->GetFurnaceRecipe(); return FR->GetBurnTime(a_Fuel); } - - - - diff --git a/src/Root.h b/src/Root.h index 2b30afaff..ab820427f 100644 --- a/src/Root.h +++ b/src/Root.h @@ -70,22 +70,31 @@ public: a_OverworldName should be set for non-overworld dimensions if one wishes that world to link back to an overworld via portals */ cWorld * CreateAndInitializeWorld(const AString & a_WorldName, eDimension a_Dimension = dimOverworld, const AString & a_OverworldName = ""); + + /** Returns the up time of the server in seconds */ + int GetServerUpTime(void) + { + return static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - m_StartTime).count()); + } // tolua_end - + /// Calls the callback for each world; returns true if the callback didn't abort (return true) bool ForEachWorld(cWorldListCallback & a_Callback); // >> Exported in ManualBindings << - + /// Writes chunkstats, for each world and totals, to the output callback void LogChunkStats(cCommandOutputCallback & a_Output); - + cMonsterConfig * GetMonsterConfig(void) { return m_MonsterConfig; } cCraftingRecipes * GetCraftingRecipes(void) { return m_CraftingRecipes; } // tolua_export cFurnaceRecipe * GetFurnaceRecipe (void) { return m_FurnaceRecipe; } // Exported in ManualBindings.cpp with quite a different signature - + /// Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel static int GetFurnaceFuelBurnTime(const cItem & a_Fuel); // tolua_export - + + /** The current time where the startup of the server has been completed */ + std::chrono::steady_clock::time_point m_StartTime; + cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export cAuthenticator & GetAuthenticator (void) { return m_Authenticator; } @@ -98,32 +107,32 @@ public: "stop" and "restart" commands have special handling. */ void QueueExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output); - + /** Queues a console command for execution through the cServer class. The command will be executed in the tick thread The command's output will be sent to console "stop" and "restart" commands have special handling. */ void QueueExecuteConsoleCommand(const AString & a_Cmd); // tolua_export - + /// Executes a console command through the cServer class; does special handling for "stop" and "restart". void ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output); - + /// Kicks the user, no matter in what world they are. Used from cAuthenticator void KickUser(int a_ClientID, const AString & a_Reason); - + /// Called by cAuthenticator to auth the specified user void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); - + /// Executes commands queued in the command queue void TickCommands(void); /// Returns the number of chunks loaded int GetTotalChunkCount(void); // tolua_export - + /// Saves all chunks in all worlds void SaveAllChunks(void); // tolua_export - + /// Calls the callback for each player in all worlds bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << @@ -132,12 +141,12 @@ public: /** Finds the player over his uuid and calls the callback */ bool DoWithPlayerByUUID(const AString & a_PlayerUUID, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << - + /** Finds the player using it's complete username and calls the callback */ bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); - + // tolua_begin - + /// Sends a chat message to all connected clients (in all worlds) void BroadcastChat (const AString & a_Message, eMessageType a_ChatPrefix = mtCustom); void BroadcastChat (const cCompositeChat & a_Message); @@ -149,18 +158,18 @@ public: void BroadcastChatLeave (const AString & a_Message) { BroadcastChat(a_Message, mtLeave); } void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(a_Message, mtSuccess); } void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(a_Message, mtWarning); } - + /// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum); - + /// Returns the amount of virtual RAM used, in KiB. Returns a negative number on error static int GetVirtualRAMUsage(void); - + /// Returns the amount of virtual RAM used, in KiB. Returns a negative number on error static int GetPhysicalRAMUsage(void); - + // tolua_end - + private: class cCommand { @@ -170,17 +179,17 @@ private: m_Output(a_Output) { } - + AString m_Command; cCommandOutputCallback * m_Output; } ; - + typedef std::map WorldMap; typedef std::vector cCommandQueue; cWorld * m_pDefaultWorld; WorldMap m_WorldsByName; - + cCriticalSection m_CSPendingCommands; cCommandQueue m_PendingCommands; @@ -206,24 +215,20 @@ private: /// Loads the worlds from settings.ini, creates the worldmap void LoadWorlds(cSettingsRepositoryInterface & a_Settings); - + /// Starts each world's life void StartWorlds(void); - + /// Stops each world's threads, so that it's safe to unload them void StopWorlds(void); - + /// Unloads all worlds from memory void UnloadWorlds(void); - + /// Does the actual work of executing a command void DoExecuteConsoleCommand(const AString & a_Cmd); - + static cRoot * s_Root; static void InputThread(cRoot & a_Params); }; // tolua_export - - - - -- cgit v1.2.3 From 31b95afd79886a90f7629b0a7038d90790660e7d Mon Sep 17 00:00:00 2001 From: tycho Date: Mon, 25 May 2015 11:10:26 +0100 Subject: Fixed ClientHandle not getting properly removed from the world when socket is closed whilst the client is being added to the world Fixes #1969 --- src/ClientHandle.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 13972b0f5..765ccdee2 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2957,13 +2957,20 @@ void cClientHandle::PacketError(UInt32 a_PacketType) void cClientHandle::SocketClosed(void) { // The socket has been closed for any reason - + if (!m_Username.empty()) // Ignore client pings { LOGD("Client %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, "Player disconnected"); } - + if (m_State < csDestroying) + { + cWorld * World = m_Player->GetWorld(); + if (World != nullptr) + { + World->RemovePlayer(m_Player, true); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again + } + } Destroy(); } -- cgit v1.2.3 From 52fcbb5c654bd0b4a0b602f9b7bebed342030e7b Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Wed, 27 May 2015 18:53:46 +0300 Subject: AI - Saner Livestock --- src/Mobs/Monster.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 1da4124ed..3fbee9a65 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -196,7 +196,15 @@ bool cMonster::TickPathFinding(cChunk & a_Chunk) { if (m_NoMoreWayPoints || (--m_GiveUpCounter == 0)) { - ResetPathFinding(); // Try to calculate a path again. + if (m_EMState == ATTACKING) + { + ResetPathFinding(); // Try to calculate a path again. + // This results in mobs hanging around an unreachable target (player). + } + else + { + StopMovingToPosition(); // Find a different place to go to. + } return false; } else if (!m_Path->IsLastPoint()) // Have we arrived at the next cell, as denoted by m_NextWayPointPosition? @@ -391,6 +399,7 @@ void cMonster::MoveToPosition(const Vector3d & a_Position) void cMonster::StopMovingToPosition() { m_IsFollowingPath = false; + ResetPathFinding(); } @@ -520,7 +529,7 @@ void cMonster::SetPitchAndYawFromDestination() double HeadRotation, HeadPitch; Distance.Normalize(); VectorToEuler(Distance.x, Distance.y, Distance.z, HeadRotation, HeadPitch); - if (std::abs(BodyRotation - HeadRotation) < 120) + if (std::abs(BodyRotation - HeadRotation) < 90) { SetHeadYaw(HeadRotation); SetPitch(-HeadPitch); -- cgit v1.2.3 From b936781f93f6d8d1421edc42444244850aa4fa18 Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Thu, 28 May 2015 08:31:17 +0300 Subject: AI - Tweaked wolf speed and teleport threshold --- src/Mobs/Wolf.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 3c2ec1520..af7de1579 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -20,6 +20,7 @@ cWolf::cWolf(void) : m_OwnerName(""), m_CollarColor(14) { + m_RelativeWalkSpeed = 2; } @@ -230,7 +231,7 @@ void cWolf::TickFollowPlayer() { // The player is present in the world, follow him: double Distance = (Callback.OwnerPos - GetPosition()).Length(); - if (Distance > 30) + if (Distance > 20) { Callback.OwnerPos.y = FindFirstNonAirBlockPosition(Callback.OwnerPos.x, Callback.OwnerPos.z); TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); -- cgit v1.2.3