summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorelectromatter <electromatter@gmail.com>2015-09-22 04:44:34 +0200
committerelectromatter <electromatter@gmail.com>2015-09-22 04:44:34 +0200
commita24cc0184343416eed86b208d8a2aff2b5c0892c (patch)
tree04ced91aa4a70b4c6e033fac4a2fc2e2ea206205 /src
parentadded bungeecord support for protocol18x (diff)
parentMerge pull request #2488 from cuberite/ChatFlag (diff)
downloadcuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.gz
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.bz2
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.lz
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.xz
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.zst
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.zip
Diffstat (limited to 'src')
-rw-r--r--src/BlockEntities/CMakeLists.txt7
-rw-r--r--src/BlockEntities/RedstonePoweredEntity.h21
-rw-r--r--src/Blocks/BlockGravel.h2
-rw-r--r--src/Blocks/BlockPlant.h5
-rw-r--r--src/Blocks/CMakeLists.txt13
-rw-r--r--src/CMakeLists.txt5
-rwxr-xr-xsrc/CheckBasicStyle.lua6
-rw-r--r--src/Chunk.cpp144
-rw-r--r--src/Chunk.h11
-rw-r--r--src/ClientHandle.cpp18
-rw-r--r--src/Color.h18
-rw-r--r--src/CompositeChat.h1
-rw-r--r--src/Globals.h20
-rw-r--r--src/Items/CMakeLists.txt7
-rw-r--r--src/Logger.cpp24
-rw-r--r--src/Logger.h59
-rw-r--r--src/LoggerListeners.cpp120
-rw-r--r--src/LoggerListeners.h26
-rw-r--r--src/OSSupport/Socket.cpp377
-rw-r--r--src/OSSupport/Socket.h125
-rw-r--r--src/Protocol/Protocol.h10
-rw-r--r--src/Protocol/Protocol17x.cpp67
-rw-r--r--src/Protocol/Protocol17x.h10
-rw-r--r--src/Protocol/Protocol18x.cpp66
-rw-r--r--src/Protocol/Protocol18x.h10
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp68
-rw-r--r--src/Protocol/ProtocolRecognizer.h10
-rw-r--r--src/Root.cpp19
-rw-r--r--src/World.cpp6
-rw-r--r--src/main.cpp5
30 files changed, 324 insertions, 956 deletions
diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt
index b0bfca5e4..0d1776eb5 100644
--- a/src/BlockEntities/CMakeLists.txt
+++ b/src/BlockEntities/CMakeLists.txt
@@ -20,7 +20,8 @@ SET (SRCS
MobHeadEntity.cpp
MobSpawnerEntity.cpp
NoteEntity.cpp
- SignEntity.cpp)
+ SignEntity.cpp
+)
SET (HDRS
BeaconEntity.h
@@ -39,7 +40,9 @@ SET (HDRS
MobHeadEntity.h
MobSpawnerEntity.h
NoteEntity.h
- SignEntity.h)
+ RedstonePoweredEntity.h
+ SignEntity.h
+)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(BeaconEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum")
diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h
index eac4e35d4..06856f3ea 100644
--- a/src/BlockEntities/RedstonePoweredEntity.h
+++ b/src/BlockEntities/RedstonePoweredEntity.h
@@ -1,13 +1,30 @@
+// RedstonePoweredEntity.h
+
+// Declares the cRedstonePoweredEntity class representing a mix-in for block entities that respond to redstone
+
+
+
+
+
#pragma once
-// Interface class representing a blockEntity that responds to redstone
+
+
+
+
+/** Interface class representing a mix-in for block entities that respond to redstone */
class cRedstonePoweredEntity
{
public:
virtual ~cRedstonePoweredEntity() {}
- /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
+ /** Sets the internal redstone power flag to "on" or "off", depending on the parameter.
+ Calls Activate() if appropriate */
virtual void SetRedstonePower(bool a_IsPowered) = 0;
};
+
+
+
+
diff --git a/src/Blocks/BlockGravel.h b/src/Blocks/BlockGravel.h
index eb101efe9..7bd68a050 100644
--- a/src/Blocks/BlockGravel.h
+++ b/src/Blocks/BlockGravel.h
@@ -19,7 +19,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
cFastRandom Random;
- if (Random.NextInt(30) == 0)
+ if (Random.NextInt(10) == 0)
{
a_Pickups.Add(E_ITEM_FLINT, 1, 0);
}
diff --git a/src/Blocks/BlockPlant.h b/src/Blocks/BlockPlant.h
index 0e6aca7eb..0155dc466 100644
--- a/src/Blocks/BlockPlant.h
+++ b/src/Blocks/BlockPlant.h
@@ -49,13 +49,12 @@ protected:
Light = Blocklight;
}
- // Return true if there is enough light
- // Set m_ShouldDie if the base light amounts are not enough to sustain a plant
+ // Based on light levels, decide between growth, stay and death:
if (Light > 8)
{
return paGrowth;
}
- else if (Blocklight < 9 && SkyLight < 9)
+ else if ((Blocklight < 9) && (SkyLight < 9))
{
return paDeath;
}
diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt
index ed3e321d4..1c12d9fbc 100644
--- a/src/Blocks/CMakeLists.txt
+++ b/src/Blocks/CMakeLists.txt
@@ -9,7 +9,8 @@ SET (SRCS
BlockDoor.cpp
BlockHandler.cpp
BlockPiston.cpp
- ChunkInterface.cpp)
+ ChunkInterface.cpp
+)
SET (HDRS
BlockAnvil.h
@@ -54,12 +55,15 @@ SET (HDRS
BlockLilypad.h
BlockMelon.h
BlockMobHead.h
+ BlockMobSpawner.h
BlockMushroom.h
BlockMycelium.h
+ BlockNetherrack.h
BlockNetherWart.h
BlockOre.h
BlockPiston.h
BlockPlanks.h
+ BlockPlant.h
BlockPluginInterface.h
BlockPortal.h
BlockPressurePlate.h
@@ -72,6 +76,7 @@ SET (HDRS
BlockRedstoneTorch.h
BlockSand.h
BlockSapling.h
+ BlockSeaLantern.h
BlockSideways.h
BlockSignPost.h
BlockSlab.h
@@ -80,8 +85,8 @@ SET (HDRS
BlockStems.h
BlockStone.h
BlockSugarcane.h
- BlockTNT.h
BlockTallGrass.h
+ BlockTNT.h
BlockTorch.h
BlockTrapdoor.h
BlockTripwire.h
@@ -92,8 +97,10 @@ SET (HDRS
BroadcastInterface.h
ChunkInterface.h
ClearMetaOnDrop.h
+ GetHandlerCompileTimeTemplate.h
MetaRotator.h
- WorldInterface.h)
+ WorldInterface.h
+)
if(NOT MSVC)
add_library(Blocks ${SRCS} ${HDRS})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a9e1a6606..d37ba5419 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -98,6 +98,7 @@ SET (HDRS
ChunkSender.h
ChunkStay.h
ClientHandle.h
+ Color.h
CommandOutput.h
CompositeChat.h
CraftingRecipes.h
@@ -316,7 +317,7 @@ if (MSVC)
OUTPUT ${BINDING_OUTPUTS}
# Copy the Lua DLL into the Bindings folder, so that tolua can run from there:
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/MCServer/lua51.dll ./lua51.dll
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/Server/lua51.dll ./lua51.dll
# Regenerate bindings:
COMMAND tolua -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
@@ -330,7 +331,7 @@ endif()
add_executable(${EXECUTABLE} ${SOURCE})
-# Output the executable into the $/MCServer folder, so that it has access to external resources:
+# Output the executable into the $/Server folder, so that it has access to external resources:
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Server)
SET_TARGET_PROPERTIES(${EXECUTABLE} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/Server
diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua
index 9521534a8..f9f8f6b4d 100755
--- a/src/CheckBasicStyle.lua
+++ b/src/CheckBasicStyle.lua
@@ -412,6 +412,12 @@ end
-- Process the files in the list:
for _, fnam in ipairs(ToProcess) do
+
+ -- Remove the optional "./" prefix:
+ if (fnam:sub(1, 2) == "./") then
+ fnam = fnam:sub(3)
+ end
+
ProcessItem(fnam)
end
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index ca7173262..7a6938b77 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -199,9 +199,9 @@ void cChunk::MarkRegenerating(void)
SetPresence(cpQueued);
// Tell all clients attached to this chunk that they want this chunk:
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto ClientHandle : m_LoadedByClient)
{
- (*itr)->AddWantedChunk(m_PosX, m_PosZ);
+ ClientHandle->AddWantedChunk(m_PosX, m_PosZ);
} // for itr - m_LoadedByClient[]
}
@@ -474,25 +474,25 @@ void cChunk::Stay(bool a_Stay)
void cChunk::CollectMobCensus(cMobCensus & toFill)
{
toFill.CollectSpawnableChunk(*this);
- std::list<const Vector3d *> playerPositions;
- cPlayer * currentPlayer;
- for (auto itr = m_LoadedByClient.begin(), end = m_LoadedByClient.end(); itr != end; ++itr)
+ std::vector<Vector3d> PlayerPositions;
+ PlayerPositions.reserve(m_LoadedByClient.size());
+ for (auto ClientHandle : m_LoadedByClient)
{
- currentPlayer = (*itr)->GetPlayer();
- playerPositions.push_back(&(currentPlayer->GetPosition()));
+ const cPlayer * currentPlayer = ClientHandle->GetPlayer();
+ PlayerPositions.push_back(currentPlayer->GetPosition());
}
Vector3d currentPosition;
- for (auto itr = m_Entities.begin(); itr != m_Entities.end(); ++itr)
+ for (auto entity : m_Entities)
{
// LOGD("Counting entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass());
- if ((*itr)->IsMob())
+ if (entity->IsMob())
{
- auto & Monster = reinterpret_cast<cMonster &>(**itr);
+ auto & Monster = reinterpret_cast<cMonster &>(*entity);
currentPosition = Monster.GetPosition();
- for (auto itr2 = playerPositions.cbegin(); itr2 != playerPositions.cend(); ++itr2)
+ for (const auto PlayerPos : PlayerPositions)
{
- toFill.CollectMob(Monster, *this, (currentPosition - **itr2).SqrLength());
+ toFill.CollectMob(Monster, *this, (currentPosition - PlayerPos).SqrLength());
}
}
} // for itr - m_Entitites[]
@@ -779,17 +779,17 @@ void cChunk::BroadcastPendingBlockChanges(void)
if (m_PendingSendBlocks.size() >= 10240)
{
// Resend the full chunk
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(), end = m_LoadedByClient.end(); itr != end; ++itr)
+ for (auto ClientHandle : m_LoadedByClient)
{
- m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM, (*itr));
+ m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM, ClientHandle);
}
}
else
{
// Only send block changes
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(), end = m_LoadedByClient.end(); itr != end; ++itr)
+ for (auto ClientHandle : m_LoadedByClient)
{
- (*itr)->SendBlockChanges(m_PosX, m_PosZ, m_PendingSendBlocks);
+ ClientHandle->SendBlockChanges(m_PosX, m_PosZ, m_PendingSendBlocks);
}
}
m_PendingSendBlocks.clear();
@@ -1758,9 +1758,9 @@ void cChunk::SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_Max
MarkDirty();
// Re-send the chunk to all clients:
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto ClientHandle : m_LoadedByClient)
{
- m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM, (*itr));
+ m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM, ClientHandle);
} // for itr - m_LoadedByClient[]
}
@@ -1856,15 +1856,13 @@ void cChunk::RemoveBlockEntity(cBlockEntity * a_BlockEntity)
bool cChunk::AddClient(cClientHandle * a_Client)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ if (std::find(m_LoadedByClient.begin(), m_LoadedByClient.end(), a_Client) != m_LoadedByClient.end())
{
- if (a_Client == *itr)
- {
- // Already there, nothing needed
- return false;
- }
+ // Already there, nothing needed
+ return false;
}
- m_LoadedByClient.push_back( a_Client);
+
+ m_LoadedByClient.push_back(a_Client);
for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr)
{
@@ -1887,31 +1885,28 @@ bool cChunk::AddClient(cClientHandle * a_Client)
void cChunk::RemoveClient(cClientHandle * a_Client)
{
- for (cClientHandleList::iterator itrC = m_LoadedByClient.begin(); itrC != m_LoadedByClient.end(); ++itrC)
+ auto itr = std::remove(m_LoadedByClient.begin(), m_LoadedByClient.end(), a_Client);
+ // We should always remove at most one client.
+ ASSERT(std::distance(itr, m_LoadedByClient.end()) <= 1);
+ // Note: itr can equal m_LoadedByClient.end()
+ m_LoadedByClient.erase(itr, m_LoadedByClient.end());
+
+ if (!a_Client->IsDestroyed())
{
- if (*itrC != a_Client)
+ for (auto Entity : m_Entities)
{
- continue;
+ /*
+ // DEBUG:
+ LOGD("chunk [%i, %i] destroying entity #%i for player \"%s\"",
+ m_PosX, m_PosZ,
+ (*itr)->GetUniqueID(), a_Client->GetUsername().c_str()
+ );
+ */
+ a_Client->SendDestroyEntity(*Entity);
}
+ }
- m_LoadedByClient.erase(itrC);
-
- if (!a_Client->IsDestroyed())
- {
- for (cEntityList::iterator itrE = m_Entities.begin(); itrE != m_Entities.end(); ++itrE)
- {
- /*
- // DEBUG:
- LOGD("chunk [%i, %i] destroying entity #%i for player \"%s\"",
- m_PosX, m_PosZ,
- (*itr)->GetUniqueID(), a_Client->GetUsername().c_str()
- );
- */
- a_Client->SendDestroyEntity(*(*itrE));
- }
- }
- return;
- } // for itr - m_LoadedByClient[]
+ return;
}
@@ -1920,14 +1915,7 @@ void cChunk::RemoveClient(cClientHandle * a_Client)
bool cChunk::HasClient(cClientHandle * a_Client)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
- {
- if ((*itr) == a_Client)
- {
- return true;
- }
- }
- return false;
+ return std::find(m_LoadedByClient.begin(), m_LoadedByClient.end(), a_Client) != m_LoadedByClient.end();
}
@@ -2793,9 +2781,9 @@ cChunk * cChunk::GetRelNeighborChunkAdjustCoords(int & a_RelX, int & a_RelZ) con
void cChunk::BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto ClientHandle : m_LoadedByClient)
{
- (*itr)->SendAttachEntity(a_Entity, a_Vehicle);
+ ClientHandle->SendAttachEntity(a_Entity, a_Vehicle);
} // for itr - LoadedByClient[]
}
@@ -2805,7 +2793,7 @@ void cChunk::BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * a_V
void cChunk::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2821,7 +2809,7 @@ void cChunk::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char
void cChunk::BroadcastBlockBreakAnimation(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2843,7 +2831,7 @@ void cChunk::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cons
{
return;
}
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2859,7 +2847,7 @@ void cChunk::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cons
void cChunk::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2875,7 +2863,7 @@ void cChunk::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_
void cChunk::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2891,7 +2879,7 @@ void cChunk::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandl
void cChunk::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2907,7 +2895,7 @@ void cChunk::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, int
void cChunk::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2923,7 +2911,7 @@ void cChunk::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum,
void cChunk::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2939,7 +2927,7 @@ void cChunk::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientHand
void cChunk::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2955,7 +2943,7 @@ void cChunk::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandle *
void cChunk::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2971,7 +2959,7 @@ void cChunk::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientHand
void cChunk::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -2987,7 +2975,7 @@ void cChunk::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, char
void cChunk::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3003,7 +2991,7 @@ void cChunk::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, c
void cChunk::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3019,7 +3007,7 @@ void cChunk::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, cons
void cChunk::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3035,7 +3023,7 @@ void cChunk::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHand
void cChunk::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3051,7 +3039,7 @@ void cChunk::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation
void cChunk::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_ParticleAmount, cClientHandle * a_Exclude)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3067,7 +3055,7 @@ void cChunk::BroadcastParticleEffect(const AString & a_ParticleName, float a_Src
void cChunk::BroadcastRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3083,7 +3071,7 @@ void cChunk::BroadcastRemoveEntityEffect(const cEntity & a_Entity, int a_EffectI
void cChunk::BroadcastSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3099,7 +3087,7 @@ void cChunk::BroadcastSoundEffect(const AString & a_SoundName, double a_X, doubl
void cChunk::BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3115,7 +3103,7 @@ void cChunk::BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY
void cChunk::BroadcastSpawnEntity(cEntity & a_Entity, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3131,7 +3119,7 @@ void cChunk::BroadcastSpawnEntity(cEntity & a_Entity, const cClientHandle * a_Ex
void cChunk::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
if (*itr == a_Exclude)
{
@@ -3147,7 +3135,7 @@ void cChunk::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, cons
void cChunk::BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ)
{
- for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
+ for (auto itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
(*itr)->SendUseBed(a_Entity, a_BlockX, a_BlockY, a_BlockZ);
} // for itr - LoadedByClient[]
diff --git a/src/Chunk.h b/src/Chunk.h
index fd9ea0b0c..6316f6910 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -439,7 +439,10 @@ public:
void SetAlwaysTicked(bool a_AlwaysTicked);
// Makes a copy of the list
- cClientHandleList GetAllClients(void) const {return m_LoadedByClient; }
+ cClientHandleList GetAllClients(void) const
+ {
+ return cClientHandleList(m_LoadedByClient.begin(), m_LoadedByClient.end());
+ }
private:
@@ -479,9 +482,9 @@ private:
sSetBlockQueueVector m_SetBlockQueue; ///< Block changes that are queued to a specific tick
// A critical section is not needed, because all chunk access is protected by its parent ChunkMap's csLayers
- cClientHandleList m_LoadedByClient;
- cEntityList m_Entities;
- cBlockEntityList m_BlockEntities;
+ std::vector<cClientHandle *> m_LoadedByClient;
+ cEntityList m_Entities;
+ cBlockEntityList m_BlockEntities;
/** Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero, the chunk can be unloaded */
int m_StayCount;
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 679dd6a46..6c9e6a781 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -2086,8 +2086,9 @@ void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefi
}
}
- AString Message = FormatMessageType(World->ShouldUseChatPrefixes(), a_ChatPrefix, a_AdditionalData);
- m_Protocol->SendChat(Message.append(a_Message));
+ bool ShouldUsePrefixes = World->ShouldUseChatPrefixes();
+ AString Message = FormatMessageType(ShouldUsePrefixes, a_ChatPrefix, a_AdditionalData);
+ m_Protocol->SendChat(Message.append(a_Message), ctChatBox, ShouldUsePrefixes);
}
@@ -2096,7 +2097,7 @@ void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefi
void cClientHandle::SendChat(const cCompositeChat & a_Message)
{
- m_Protocol->SendChat(a_Message);
+ m_Protocol->SendChat(a_Message, ctChatBox, GetPlayer()->GetWorld()->ShouldUseChatPrefixes());
}
@@ -2116,7 +2117,7 @@ void cClientHandle::SendChatAboveActionBar(const AString & a_Message, eMessageTy
}
AString Message = FormatMessageType(World->ShouldUseChatPrefixes(), a_ChatPrefix, a_AdditionalData);
- m_Protocol->SendChatAboveActionBar(Message.append(a_Message));
+ m_Protocol->SendChat(Message.append(a_Message), ctAboveActionBar);
}
@@ -2125,7 +2126,7 @@ void cClientHandle::SendChatAboveActionBar(const AString & a_Message, eMessageTy
void cClientHandle::SendChatAboveActionBar(const cCompositeChat & a_Message)
{
- m_Protocol->SendChatAboveActionBar(a_Message);
+ m_Protocol->SendChat(a_Message, ctAboveActionBar, GetPlayer()->GetWorld()->ShouldUseChatPrefixes());
}
@@ -2144,8 +2145,9 @@ void cClientHandle::SendChatSystem(const AString & a_Message, eMessageType a_Cha
}
}
- AString Message = FormatMessageType(World->ShouldUseChatPrefixes(), a_ChatPrefix, a_AdditionalData);
- m_Protocol->SendChatSystem(Message.append(a_Message));
+ auto ShouldUsePrefixes = World->ShouldUseChatPrefixes();
+ AString Message = FormatMessageType(ShouldUsePrefixes, a_ChatPrefix, a_AdditionalData);
+ m_Protocol->SendChat(Message.append(a_Message), ctSystem, ShouldUsePrefixes);
}
@@ -2154,7 +2156,7 @@ void cClientHandle::SendChatSystem(const AString & a_Message, eMessageType a_Cha
void cClientHandle::SendChatSystem(const cCompositeChat & a_Message)
{
- m_Protocol->SendChatSystem(a_Message);
+ m_Protocol->SendChat(a_Message, ctSystem, GetPlayer()->GetWorld()->ShouldUseChatPrefixes());
}
diff --git a/src/Color.h b/src/Color.h
index 57775b0dd..3680193ab 100644
--- a/src/Color.h
+++ b/src/Color.h
@@ -25,31 +25,31 @@ public:
cColor() { m_Color = static_cast<unsigned int>(COLOR_NONE);}
cColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue) { SetColor(a_Red, a_Green, a_Blue); }
- /// Returns whether the color is a valid color
+ /** Returns whether the color is a valid color */
bool IsValid() const { return m_Color != COLOR_NONE; }
- /// Changes the color
+ /** Changes the color */
void SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue);
- /// Alters the red value of the color
+ /** Alters the red value of the color */
void SetRed(unsigned char a_Red);
- /// Alters the green value of the color
+ /** Alters the green value of the color */
void SetGreen(unsigned char a_Red);
- /// Alters the blue value of the color
+ /** Alters the blue value of the color */
void SetBlue(unsigned char a_Red);
- /// Returns the red value of the color
+ /** Returns the red value of the color */
unsigned char GetRed() const;
- /// Returns the green value of the color
+ /** Returns the green value of the color */
unsigned char GetGreen() const;
- /// Returns the blue value of the color
+ /** Returns the blue value of the color */
unsigned char GetBlue() const;
- /// Resets the color
+ /** Resets the color */
void Clear() { m_Color = static_cast<unsigned int>(COLOR_NONE); }
// tolua_end
diff --git a/src/CompositeChat.h b/src/CompositeChat.h
index 369eed196..becf0a91e 100644
--- a/src/CompositeChat.h
+++ b/src/CompositeChat.h
@@ -5,6 +5,7 @@
#include "Defines.h"
#include "json/json.h"
+#include "Logger.h"
diff --git a/src/Globals.h b/src/Globals.h
index 1afcc928c..a69a64452 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -271,7 +271,25 @@ template class SizeChecker<UInt8, 1>;
#include "OSSupport/StackTrace.h"
#ifndef TEST_GLOBALS
- #include "Logger.h"
+
+// These fiunctions are defined in Logger.cpp, but are declared here to avoid including all of logger.h
+extern void LOG (const char * a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGINFO (const char * a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGWARNING(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 LOGWARN LOGWARNING
#else
// Logging functions
void inline LOGERROR(const char * a_Format, ...) FORMATSTRING(1, 2);
diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt
index 46ff3b4a0..91083d31b 100644
--- a/src/Items/CMakeLists.txt
+++ b/src/Items/CMakeLists.txt
@@ -5,7 +5,8 @@ project (MCServer)
include_directories ("${PROJECT_SOURCE_DIR}/../")
SET (SRCS
- ItemHandler.cpp)
+ ItemHandler.cpp
+)
SET (HDRS
ItemArmor.h
@@ -26,6 +27,7 @@ SET (HDRS
ItemFishingRod.h
ItemFlowerPot.h
ItemFood.h
+ ItemGoldenApple.h
ItemHandler.h
ItemHoe.h
ItemItemFrame.h
@@ -36,6 +38,7 @@ SET (HDRS
ItemMilk.h
ItemMinecart.h
ItemMobHead.h
+ ItemMushroomSoup.h
ItemNetherWart.h
ItemPainting.h
ItemPickaxe.h
@@ -47,8 +50,8 @@ SET (HDRS
ItemSeeds.h
ItemShears.h
ItemShovel.h
- ItemSlab.h
ItemSign.h
+ ItemSlab.h
ItemSpawnEgg.h
ItemString.h
ItemSugarcane.h
diff --git a/src/Logger.cpp b/src/Logger.cpp
index 292622a46..60f5a88d2 100644
--- a/src/Logger.cpp
+++ b/src/Logger.cpp
@@ -1,5 +1,6 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "Logger.h"
#include "OSSupport/IsThread.h"
#ifdef _WIN32
@@ -73,10 +74,14 @@ void cLogger::Log(const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList
-void cLogger::AttachListener(cListener * a_Listener)
+cLogger::cAttachment cLogger::AttachListener(std::unique_ptr<cListener> a_Listener)
{
- cCSLock Lock(m_CriticalSection);
- m_LogListeners.push_back(a_Listener);
+ auto nonOwning = a_Listener.get();
+ {
+ cCSLock Lock(m_CriticalSection);
+ m_LogListeners.push_back(std::move(a_Listener));
+ }
+ return cAttachment{nonOwning};
}
@@ -86,7 +91,16 @@ void cLogger::AttachListener(cListener * 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));
+ m_LogListeners.erase(
+ std::remove_if(
+ m_LogListeners.begin(),
+ m_LogListeners.end(),
+ [=](std::unique_ptr<cListener> & a_OtherListener) -> bool
+ {
+ return a_OtherListener.get() == a_Listener;
+ }
+ )
+ );
}
@@ -120,7 +134,7 @@ void LOGINFO(const char * a_Format, ...)
-void LOGWARN(const char * a_Format, ...)
+void LOGWARNING(const char * a_Format, ...)
{
va_list argList;
va_start(argList, a_Format);
diff --git a/src/Logger.h b/src/Logger.h
index 176c6e810..a0c2917a9 100644
--- a/src/Logger.h
+++ b/src/Logger.h
@@ -23,13 +23,35 @@ public:
virtual ~cListener(){}
};
+ class cAttachment
+ {
+ public:
+
+ cAttachment(cAttachment && a_other)
+ : m_listener(a_other.m_listener)
+ {
+ }
+
+ ~cAttachment()
+ {
+ cLogger::GetInstance().DetachListener(m_listener);
+ }
+
+ private:
+
+ cListener * m_listener;
+
+ friend class cLogger;
+
+ cAttachment(cListener * a_listener) : m_listener(a_listener) {}
+ };
+
void Log (const char * a_Format, 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);
- void AttachListener(cListener * a_Listener);
- void DetachListener(cListener * a_Listener);
+ cAttachment AttachListener(std::unique_ptr<cListener> a_Listener);
static cLogger & GetInstance(void);
// Must be called before calling GetInstance in a multithreaded context
@@ -37,37 +59,20 @@ public:
private:
cCriticalSection m_CriticalSection;
- std::vector<cListener *> 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
+ std::vector<std::unique_ptr<cListener>> m_LogListeners;
+ void DetachListener(cListener * a_Listener);
+};
-#define LOGWARNING LOGWARN
+// These declarations are duplicated in globals.h
+extern void LOG (const char * a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGINFO (const char * a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGWARNING(const char * a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGERROR (const char * a_Format, ...) FORMATSTRING(1, 2);
diff --git a/src/LoggerListeners.cpp b/src/LoggerListeners.cpp
index ba8139678..3b6ed2147 100644
--- a/src/LoggerListeners.cpp
+++ b/src/LoggerListeners.cpp
@@ -251,11 +251,11 @@ class cNullConsoleListener
-cLogger::cListener * MakeConsoleListener(bool a_IsService)
+std::unique_ptr<cLogger::cListener> MakeConsoleListener(bool a_IsService)
{
if (a_IsService)
{
- return new cNullConsoleListener;
+ return cpp14::make_unique<cNullConsoleListener>();
}
#ifdef _WIN32
@@ -267,25 +267,25 @@ cLogger::cListener * MakeConsoleListener(bool a_IsService)
HANDLE Console = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(Console, &sbi);
WORD DefaultConsoleAttrib = sbi.wAttributes;
- return new cWindowsConsoleListener(Console, DefaultConsoleAttrib);
+ return cpp14::make_unique<cWindowsConsoleListener>(Console, DefaultConsoleAttrib);
}
else
{
- return new cVanillaCPPConsoleListener;
+ return cpp14::make_unique<cVanillaCPPConsoleListener>();
}
#elif defined (__linux) && !defined(ANDROID_NDK)
// TODO: lookup terminal in terminfo
if (isatty(fileno(stdout)))
{
- return new cLinuxConsoleListener();
+ return cpp14::make_unique<cLinuxConsoleListener>();
}
else
{
- return new cVanillaCPPConsoleListener();
+ return cpp14::make_unique<cVanillaCPPConsoleListener>();
}
#else
- return new cVanillaCPPConsoleListener();
+ return cpp14::make_unique<cVanillaCPPConsoleListener>();
#endif
}
@@ -296,60 +296,82 @@ cLogger::cListener * MakeConsoleListener(bool a_IsService)
////////////////////////////////////////////////////////////////////////////////
// cFileListener:
-cFileListener::cFileListener(void)
+class cFileListener
+ : public cLogger::cListener
{
- cFile::CreateFolder(FILE_IO_PREFIX + AString("logs"));
- m_File.Open(
- FILE_IO_PREFIX + Printf(
- "logs/LOG_%d.txt",
- std::chrono::duration_cast<std::chrono::duration<int, std::ratio<1>>>(
- std::chrono::system_clock::now().time_since_epoch()
- ).count()
- ),
- cFile::fmAppend
- );
-}
-
-
+public:
+ cFileListener(void) {}
+ bool Open()
+ {
+ // Assume creation succeeds, as the API does not provide a way to tell if the folder exists.
+ cFile::CreateFolder(FILE_IO_PREFIX + AString("logs"));
+ bool success = m_File.Open(
+ FILE_IO_PREFIX + Printf(
+ "logs/LOG_%d.txt",
+ std::chrono::duration_cast<std::chrono::duration<int, std::ratio<1>>>(
+ std::chrono::system_clock::now().time_since_epoch()
+ ).count()
+ ),
+ cFile::fmAppend
+ );
+ return success;
+ }
-void cFileListener::Log(AString a_Message, cLogger::eLogLevel a_LogLevel)
-{
- const char * LogLevelPrefix = "Unkn ";
- bool ShouldFlush = false;
- switch (a_LogLevel)
+ virtual void Log(AString a_Message, cLogger::eLogLevel a_LogLevel) override
{
- case cLogger::llRegular:
- {
- LogLevelPrefix = " ";
- break;
- }
- case cLogger::llInfo:
- {
- LogLevelPrefix = "Info ";
- break;
- }
- case cLogger::llWarning:
+ const char * LogLevelPrefix = "Unkn ";
+ bool ShouldFlush = false;
+ switch (a_LogLevel)
{
- LogLevelPrefix = "Warn ";
- ShouldFlush = true;
- break;
+ case cLogger::llRegular:
+ {
+ LogLevelPrefix = " ";
+ break;
+ }
+ case cLogger::llInfo:
+ {
+ LogLevelPrefix = "Info ";
+ break;
+ }
+ case cLogger::llWarning:
+ {
+ LogLevelPrefix = "Warn ";
+ ShouldFlush = true;
+ break;
+ }
+ case cLogger::llError:
+ {
+ LogLevelPrefix = "Err ";
+ ShouldFlush = true;
+ break;
+ }
}
- case cLogger::llError:
+ m_File.Printf("%s%s", LogLevelPrefix, a_Message.c_str());
+ if (ShouldFlush)
{
- LogLevelPrefix = "Err ";
- ShouldFlush = true;
- break;
+ m_File.Flush();
}
}
- m_File.Printf("%s%s", LogLevelPrefix, a_Message.c_str());
- if (ShouldFlush)
+
+private:
+
+ cFile m_File;
+};
+
+
+
+
+
+std::pair<bool, std::unique_ptr<cLogger::cListener>> MakeFileListener()
+{
+ auto listener = cpp14::make_unique<cFileListener>();
+ if (!listener->Open())
{
- m_File.Flush();
+ return {false, nullptr};
}
+ return {true, std::move(listener)};
}
-
-
diff --git a/src/LoggerListeners.h b/src/LoggerListeners.h
index a7f9a35a5..3d5628caa 100644
--- a/src/LoggerListeners.h
+++ b/src/LoggerListeners.h
@@ -2,30 +2,8 @@
#include "Logger.h"
#include "OSSupport/File.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(bool a_IsService);
+std::unique_ptr<cLogger::cListener> MakeConsoleListener(bool a_IsService);
+std::pair<bool, std::unique_ptr<cLogger::cListener>> MakeFileListener();
diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp
deleted file mode 100644
index 5025a09ad..000000000
--- a/src/OSSupport/Socket.cpp
+++ /dev/null
@@ -1,377 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "Socket.h"
-
-#ifndef _WIN32
- #include <netdb.h>
- #include <unistd.h>
- #include <arpa/inet.h> // inet_ntoa()
- #include <sys/ioctl.h> // ioctl()
-#else
- #define socklen_t int
-#endif
-
-
-
-
-
-cSocket::cSocket(xSocket a_Socket)
- : m_Socket(a_Socket)
-{
-}
-
-
-
-
-
-cSocket::operator cSocket::xSocket() const
-{
- return m_Socket;
-}
-
-
-
-
-
-cSocket::xSocket cSocket::GetSocket() const
-{
- return m_Socket;
-}
-
-
-
-
-
-bool cSocket::IsValidSocket(cSocket::xSocket a_Socket)
-{
- #ifdef _WIN32
- return (a_Socket != INVALID_SOCKET);
- #else // _WIN32
- return (a_Socket >= 0);
- #endif // else _WIN32
-}
-
-
-
-
-
-void cSocket::CloseSocket()
-{
- #ifdef _WIN32
-
- closesocket(m_Socket);
-
- #else // _WIN32
-
- if (close(m_Socket) != 0)
- {
- LOGWARN("Error closing socket %d (%s): %s", m_Socket, m_IPString.c_str(), GetLastErrorString().c_str());
- }
-
- #endif // else _WIN32
-
- // Invalidate the socket so that this object can be re-used for another connection
- m_Socket = INVALID_SOCKET;
-}
-
-
-
-
-
-void cSocket::ShutdownReadWrite(void)
-{
- #ifdef _WIN32
- int res = shutdown(m_Socket, SD_BOTH);
- #else
- int res = shutdown(m_Socket, SHUT_RDWR);
- #endif
- if (res != 0)
- {
- LOGWARN("%s: Error shutting down socket %d (%s): %d (%s)",
- __FUNCTION__, m_Socket, m_IPString.c_str(), this->GetLastError(), GetLastErrorString().c_str()
- );
- }
-}
-
-
-
-
-int cSocket::GetLastError()
-{
-#ifdef _WIN32
- return WSAGetLastError();
-#else
- return errno;
-#endif
-}
-
-
-
-
-
-bool cSocket::SetReuseAddress(void)
-{
- #if defined(_WIN32) || defined(ANDROID_NDK)
- char yes = 1;
- #else
- int yes = 1;
- #endif
- return (setsockopt(m_Socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == 0);
-}
-
-
-
-
-
-int cSocket::WSAStartup(void)
-{
-#ifdef _WIN32
- WSADATA wsaData;
- memset(&wsaData, 0, sizeof(wsaData));
- return ::WSAStartup(MAKEWORD(2, 2), &wsaData);
-#else
- return 0;
-#endif
-}
-
-
-
-
-
-cSocket cSocket::CreateSocket(eFamily a_Family)
-{
- return socket((int)a_Family, SOCK_STREAM, 0);
-}
-
-
-
-
-
-bool cSocket::BindToAnyIPv4(unsigned short a_Port)
-{
- sockaddr_in local;
- memset(&local, 0, sizeof(local));
-
- local.sin_family = AF_INET;
- local.sin_port = htons((u_short)a_Port);
-
- return (bind(m_Socket, (sockaddr *)&local, sizeof(local)) == 0);
-}
-
-
-
-
-
-bool cSocket::BindToAnyIPv6(unsigned short a_Port)
-{
- sockaddr_in6 local;
- memset(&local, 0, sizeof(local));
-
- local.sin6_family = AF_INET6;
- local.sin6_port = htons((u_short)a_Port);
-
- return (bind(m_Socket, (sockaddr *)&local, sizeof(local)) == 0);
-}
-
-
-
-
-
-bool cSocket::BindToLocalhostIPv4(unsigned short a_Port)
-{
- sockaddr_in local;
- memset(&local, 0, sizeof(local));
-
- local.sin_family = AF_INET;;
- local.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- local.sin_port = htons((u_short)a_Port);
-
- return (bind(m_Socket, (sockaddr*)&local, sizeof(local)) == 0);
-}
-
-
-
-
-
-bool cSocket::Listen(int a_Backlog)
-{
- return (listen(m_Socket, a_Backlog) == 0);
-}
-
-
-
-
-
-cSocket cSocket::AcceptIPv4(void)
-{
- sockaddr_in from;
- socklen_t fromlen = sizeof(from);
-
- cSocket SClient = accept(m_Socket, (sockaddr *)&from, &fromlen);
-
- if (SClient.IsValid() && (from.sin_addr.s_addr != 0)) // Get IP in string form
- {
- SClient.m_IPString = inet_ntoa(from.sin_addr);
- }
- return SClient;
-}
-
-
-
-
-
-cSocket cSocket::AcceptIPv6(void)
-{
- sockaddr_in6 from;
- socklen_t fromlen = sizeof(from);
-
- cSocket SClient = accept(m_Socket, (sockaddr *)&from, &fromlen);
-
- // Get IP in string form:
- if (SClient.IsValid())
- {
- #if defined(_WIN32)
- // Windows XP doesn't have inet_ntop, so we need to improvise. And MSVC has different headers than GCC
- #ifdef _MSC_VER
- // MSVC version
- Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x",
- from.sin6_addr.u.Word[0],
- from.sin6_addr.u.Word[1],
- from.sin6_addr.u.Word[2],
- from.sin6_addr.u.Word[3],
- from.sin6_addr.u.Word[4],
- from.sin6_addr.u.Word[5],
- from.sin6_addr.u.Word[6],
- from.sin6_addr.u.Word[7]
- );
- #else // _MSC_VER
- // MinGW
- Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x",
- from.sin6_addr.s6_addr16[0],
- from.sin6_addr.s6_addr16[1],
- from.sin6_addr.s6_addr16[2],
- from.sin6_addr.s6_addr16[3],
- from.sin6_addr.s6_addr16[4],
- from.sin6_addr.s6_addr16[5],
- from.sin6_addr.s6_addr16[6],
- from.sin6_addr.s6_addr16[7]
- );
- #endif // else _MSC_VER
- #else
- char buffer[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET6, &(from.sin6_addr), buffer, sizeof(buffer));
- SClient.m_IPString.assign(buffer);
- #endif // _WIN32
- }
- return SClient;
-}
-
-
-
-
-
-bool cSocket::ConnectToLocalhostIPv4(unsigned short a_Port)
-{
- sockaddr_in server;
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- server.sin_port = htons(a_Port);
- return (connect(m_Socket, (sockaddr *)&server, sizeof(server)) == 0);
-}
-
-
-
-
-
-bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Port)
-{
- // First try IP Address string to hostent conversion, because it's faster and local:
- unsigned long addr = inet_addr(a_HostNameOrAddr.c_str());
- if (addr == INADDR_NONE)
- {
- // It is not an IP Address string, but rather a regular hostname, resolve:
- hostent * hp = gethostbyname(a_HostNameOrAddr.c_str());
- if (hp == nullptr)
- {
- LOGWARNING("%s: Could not resolve hostname \"%s\"", __FUNCTION__, a_HostNameOrAddr.c_str());
- CloseSocket();
- return false;
- }
- memcpy(&addr, hp->h_addr, hp->h_length);
- }
-
- // If the socket is not created yet, create one:
- if (!IsValid())
- {
- m_Socket = socket((int)IPv4, SOCK_STREAM, 0);
- }
-
- // Connect the socket:
- sockaddr_in server;
- server.sin_addr.s_addr = addr;
- server.sin_family = AF_INET;
- server.sin_port = htons((unsigned short)a_Port);
- return (connect(m_Socket, (sockaddr *)&server, sizeof(server)) == 0);
-}
-
-
-
-
-
-int cSocket::Receive(char * a_Buffer, size_t a_Length, unsigned int a_Flags)
-{
- return recv(m_Socket, a_Buffer, (int)a_Length, a_Flags);
-}
-
-
-
-
-
-int cSocket::Send(const char * a_Buffer, size_t a_Length)
-{
- return send(m_Socket, a_Buffer, (int)a_Length, MSG_NOSIGNAL);
-}
-
-
-
-
-
-unsigned short cSocket::GetPort(void) const
-{
- ASSERT(IsValid());
-
- sockaddr_in Addr;
- socklen_t AddrSize = sizeof(Addr);
- if (getsockname(m_Socket, (sockaddr *)&Addr, &AddrSize) != 0)
- {
- return 0;
- }
- return ntohs(Addr.sin_port);
-}
-
-
-
-
-
-void cSocket::SetNonBlocking(void)
-{
- #ifdef _WIN32
- u_long NonBlocking = 1;
- int res = ioctlsocket(m_Socket, FIONBIO, &NonBlocking);
- #else
- int NonBlocking = 1;
- int res = ioctl(m_Socket, FIONBIO, (char *)&NonBlocking);
- #endif
- if (res != 0)
- {
- LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s",
- res, GetLastError(), GetLastErrorString().c_str()
- );
- abort();
- }
-}
-
-
-
-
diff --git a/src/OSSupport/Socket.h b/src/OSSupport/Socket.h
deleted file mode 100644
index 9ec8c1111..000000000
--- a/src/OSSupport/Socket.h
+++ /dev/null
@@ -1,125 +0,0 @@
-
-#pragma once
-
-
-
-
-
-// Windows and MacOSX don't have the MSG_NOSIGNAL flag
-#if ( \
- defined(_WIN32) || \
- (defined(__APPLE__) && defined(__MACH__)) \
-)
- #define MSG_NOSIGNAL (0)
-#endif
-
-
-#include "Errors.h"
-
-
-class cSocket
-{
-public:
- enum eFamily
- {
- IPv4 = AF_INET,
- IPv6 = AF_INET6,
-
- #ifdef _WIN32
- ErrWouldBlock = WSAEWOULDBLOCK,
- #else
- ErrWouldBlock = EWOULDBLOCK,
- #endif
- } ;
-
-#ifdef _WIN32
- typedef SOCKET xSocket;
-#else
- typedef int xSocket;
- static const int INVALID_SOCKET = -1;
-#endif
-
- cSocket(void) : m_Socket(INVALID_SOCKET) {}
- cSocket(xSocket a_Socket);
-
- bool IsValid(void) const { return IsValidSocket(m_Socket); }
- void CloseSocket(void);
-
- /** Notifies the socket that we don't expect any more reads nor writes on it.
- Most TCPIP implementations use this to send the FIN flag in a packet */
- void ShutdownReadWrite(void);
-
- operator xSocket(void) const;
- xSocket GetSocket(void) const;
-
- bool operator == (const cSocket & a_Other) {return m_Socket == a_Other.m_Socket; }
-
- void SetSocket(xSocket a_Socket);
-
- /// Sets the address-reuse socket flag; returns true on success
- bool SetReuseAddress(void);
-
- /// Initializes the network stack. Returns 0 on success, or another number as an error code.
- static int WSAStartup(void);
-
- static int GetLastError();
- static AString GetLastErrorString(void)
- {
- return GetOSErrorString(GetLastError());
- }
-
- /// Creates a new socket of the specified address family
- static cSocket CreateSocket(eFamily a_Family);
-
- inline static bool IsSocketError(int a_ReturnedValue)
- {
- #ifdef _WIN32
- return ((a_ReturnedValue == SOCKET_ERROR) || (a_ReturnedValue == 0));
- #else
- return (a_ReturnedValue <= 0);
- #endif
- }
-
- static bool IsValidSocket(xSocket a_Socket);
-
- static const unsigned short ANY_PORT = 0; // When given to Bind() functions, they will find a free port
- static const int DEFAULT_BACKLOG = 10;
-
- /// Binds to the specified port on "any" interface (0.0.0.0). Returns true if successful.
- bool BindToAnyIPv4(unsigned short a_Port);
-
- /// Binds to the specified port on "any" interface (::/128). Returns true if successful.
- bool BindToAnyIPv6(unsigned short a_Port);
-
- /// Binds to the specified port on localhost interface (127.0.0.1) through IPv4. Returns true if successful.
- bool BindToLocalhostIPv4(unsigned short a_Port);
-
- /// Sets the socket to listen for incoming connections. Returns true if successful.
- bool Listen(int a_Backlog = DEFAULT_BACKLOG);
-
- /// Accepts an IPv4 incoming connection. Blocks if none available.
- cSocket AcceptIPv4(void);
-
- /// Accepts an IPv6 incoming connection. Blocks if none available.
- cSocket AcceptIPv6(void);
-
- /// Connects to a localhost socket on the specified port using IPv4; returns true if successful.
- bool ConnectToLocalhostIPv4(unsigned short a_Port);
-
- /// Connects to the specified host or string IP address and port, using IPv4. Returns true if successful.
- bool ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Port);
-
- int Receive(char * a_Buffer, size_t a_Length, unsigned int a_Flags);
- int Send (const char * a_Buffer, size_t a_Length);
-
- unsigned short GetPort(void) const; // Returns 0 on failure
-
- const AString & GetIPString(void) const { return m_IPString; }
-
- /** Sets the socket into non-blocking mode */
- void SetNonBlocking(void);
-
-private:
- xSocket m_Socket;
- AString m_IPString;
-};
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index 9153ec8ae..4581da6a9 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -68,14 +68,8 @@ public:
virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) = 0;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) = 0;
- virtual void SendChat (const AString & a_Message) = 0;
- virtual void SendChat (const cCompositeChat & a_Message) = 0;
- virtual void SendChatAboveActionBar (const AString & a_Message) = 0;
- virtual void SendChatAboveActionBar (const cCompositeChat & a_Message) = 0;
- virtual void SendChatSystem (const AString & a_Message) = 0;
- virtual void SendChatSystem (const cCompositeChat & a_Message) = 0;
- virtual void SendChatType (const AString & a_Message, eChatType type) = 0;
- virtual void SendChatType (const cCompositeChat & a_Message, eChatType type) = 0;
+ virtual void SendChat (const AString & a_Message, eChatType a_Type) = 0;
+ virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) = 0;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) = 0;
virtual void SendDestroyEntity (const cEntity & a_Entity) = 0;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 3ac656d47..ad76480b3 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -245,65 +245,11 @@ void cProtocol172::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV
-void cProtocol172::SendChat(const AString & a_Message)
-{
- this->SendChatType(a_Message, ctChatBox);
-}
-
-
-
-
-
-void cProtocol172::SendChat(const cCompositeChat & a_Message)
-{
- this->SendChatType(a_Message, ctChatBox);
-}
-
-
-
-
-
-void cProtocol172::SendChatSystem(const AString & a_Message)
-{
- this->SendChatType(a_Message, ctSystem);
-}
-
-
-
-
-
-void cProtocol172::SendChatSystem(const cCompositeChat & a_Message)
-{
- this->SendChatType(a_Message, ctSystem);
-}
-
-
-
-
-
-void cProtocol172::SendChatAboveActionBar(const AString & a_Message)
-{
- this->SendChatType(a_Message, ctAboveActionBar);
-}
-
-
-
-
-
-void cProtocol172::SendChatAboveActionBar(const cCompositeChat & a_Message)
-{
- this->SendChatType(a_Message, ctAboveActionBar);
-}
-
-
-
-
-
-void cProtocol172::SendChatType(const AString & a_Message, eChatType type)
+void cProtocol172::SendChat(const AString & a_Message, eChatType a_Type)
{
ASSERT(m_State == 3); // In game mode?
- if (type != ctChatBox) // 1.7.2 doesn't support anything else
+ if (a_Type != ctChatBox) // 1.7.2 doesn't support anything else
{
return;
}
@@ -316,21 +262,18 @@ void cProtocol172::SendChatType(const AString & a_Message, eChatType type)
-void cProtocol172::SendChatType(const cCompositeChat & a_Message, eChatType type)
+void cProtocol172::SendChat(const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes)
{
ASSERT(m_State == 3); // In game mode?
- if (type != ctChatBox) // 1.7.2 doesn't support anything else
+ if (a_Type != ctChatBox) // 1.7.2 doesn't support anything else
{
return;
}
- cWorld * World = m_Client->GetPlayer()->GetWorld();
- bool ShouldUseChatPrefixes = (World == nullptr) ? false : World->ShouldUseChatPrefixes();
-
// Send the message to the client:
cPacketizer Pkt(*this, 0x02);
- Pkt.WriteString(a_Message.CreateJsonString(ShouldUseChatPrefixes));
+ Pkt.WriteString(a_Message.CreateJsonString(a_ShouldUseChatPrefixes));
}
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index 9d2d108dc..cc201f840 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -66,14 +66,8 @@ public:
virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
- virtual void SendChat (const AString & a_Message) override;
- virtual void SendChat (const cCompositeChat & a_Message) override;
- virtual void SendChatAboveActionBar (const AString & a_Message) override;
- virtual void SendChatAboveActionBar (const cCompositeChat & a_Message) override;
- virtual void SendChatSystem (const AString & a_Message) override;
- virtual void SendChatSystem (const cCompositeChat & a_Message) override;
- virtual void SendChatType (const AString & a_Message, eChatType type) override;
- virtual void SendChatType (const cCompositeChat & a_Message, eChatType type) override;
+ virtual void SendChat (const AString & a_Message, eChatType a_Type) override;
+ virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
virtual void SendDestroyEntity (const cEntity & a_Entity) override;
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index 7a754abce..d69c631d2 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -246,84 +246,28 @@ void cProtocol180::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV
-void cProtocol180::SendChat(const AString & a_Message)
-{
- this->SendChatType(a_Message, ctChatBox);
-}
-
-
-
-
-
-void cProtocol180::SendChat(const cCompositeChat & a_Message)
-{
- this->SendChatType(a_Message, ctChatBox);
-}
-
-
-
-
-
-void cProtocol180::SendChatSystem(const AString & a_Message)
-{
- this->SendChatType(a_Message, ctSystem);
-}
-
-
-
-
-
-void cProtocol180::SendChatSystem(const cCompositeChat & a_Message)
-{
- this->SendChatType(a_Message, ctSystem);
-}
-
-
-
-
-
-void cProtocol180::SendChatAboveActionBar(const AString & a_Message)
-{
- this->SendChatType(a_Message, ctAboveActionBar);
-}
-
-
-
-
-
-void cProtocol180::SendChatAboveActionBar(const cCompositeChat & a_Message)
-{
- this->SendChatType(a_Message, ctAboveActionBar);
-}
-
-
-
-
-
-void cProtocol180::SendChatType(const AString & a_Message, eChatType type)
+void cProtocol180::SendChat(const AString & a_Message, eChatType a_Type)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x02); // Chat Message packet
Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Message).c_str()));
- Pkt.WriteBEInt8(type);
+ Pkt.WriteBEInt8(a_Type);
}
-void cProtocol180::SendChatType(const cCompositeChat & a_Message, eChatType type)
+void cProtocol180::SendChat(const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes)
{
ASSERT(m_State == 3); // In game mode?
- cWorld * World = m_Client->GetPlayer()->GetWorld();
- bool ShouldUseChatPrefixes = (World == nullptr) ? false : World->ShouldUseChatPrefixes();
// Send the message to the client:
cPacketizer Pkt(*this, 0x02);
- Pkt.WriteString(a_Message.CreateJsonString(ShouldUseChatPrefixes));
- Pkt.WriteBEInt8(type);
+ Pkt.WriteString(a_Message.CreateJsonString(a_ShouldUseChatPrefixes));
+ Pkt.WriteBEInt8(a_Type);
}
diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h
index 02add5528..aa73a4a6a 100644
--- a/src/Protocol/Protocol18x.h
+++ b/src/Protocol/Protocol18x.h
@@ -65,14 +65,8 @@ public:
virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
- virtual void SendChat (const AString & a_Message) override;
- virtual void SendChat (const cCompositeChat & a_Message) override;
- virtual void SendChatAboveActionBar (const AString & a_Message) override;
- virtual void SendChatAboveActionBar (const cCompositeChat & a_Message) override;
- virtual void SendChatSystem (const AString & a_Message) override;
- virtual void SendChatSystem (const cCompositeChat & a_Message) override;
- virtual void SendChatType (const AString & a_Message, eChatType type) override;
- virtual void SendChatType (const cCompositeChat & a_Message, eChatType type) override;
+ virtual void SendChat (const AString & a_Message, eChatType a_Type) override;
+ virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
virtual void SendDestroyEntity (const cEntity & a_Entity) override;
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index 42c2eee0a..0d16262f9 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -138,80 +138,20 @@ void cProtocolRecognizer::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSe
-void cProtocolRecognizer::SendChat(const AString & a_Message)
+void cProtocolRecognizer::SendChat(const AString & a_Message, eChatType a_Type)
{
ASSERT(m_Protocol != nullptr);
- m_Protocol->SendChat(a_Message);
+ m_Protocol->SendChat(a_Message, a_Type);
}
-void cProtocolRecognizer::SendChat(const cCompositeChat & a_Message)
+void cProtocolRecognizer::SendChat(const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes)
{
ASSERT(m_Protocol != nullptr);
- m_Protocol->SendChat(a_Message);
-}
-
-
-
-
-
-void cProtocolRecognizer::SendChatAboveActionBar(const AString & a_Message)
-{
- ASSERT(m_Protocol != nullptr);
- m_Protocol->SendChatAboveActionBar(a_Message);
-}
-
-
-
-
-
-void cProtocolRecognizer::SendChatAboveActionBar(const cCompositeChat & a_Message)
-{
- ASSERT(m_Protocol != nullptr);
- m_Protocol->SendChatAboveActionBar(a_Message);
-}
-
-
-
-
-
-void cProtocolRecognizer::SendChatSystem(const AString & a_Message)
-{
- ASSERT(m_Protocol != nullptr);
- m_Protocol->SendChatSystem(a_Message);
-}
-
-
-
-
-
-void cProtocolRecognizer::SendChatSystem(const cCompositeChat & a_Message)
-{
- ASSERT(m_Protocol != nullptr);
- m_Protocol->SendChatSystem(a_Message);
-}
-
-
-
-
-
-void cProtocolRecognizer::SendChatType(const AString & a_Message, eChatType type)
-{
- ASSERT(m_Protocol != nullptr);
- m_Protocol->SendChatType(a_Message, type);
-}
-
-
-
-
-
-void cProtocolRecognizer::SendChatType(const cCompositeChat & a_Message, eChatType type)
-{
- ASSERT(m_Protocol != nullptr);
- m_Protocol->SendChatType(a_Message, type);
+ m_Protocol->SendChat(a_Message, a_Type, a_ShouldUseChatPrefixes);
}
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index d3cfd9bf7..7b5952bea 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -53,14 +53,8 @@ public:
virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
- virtual void SendChat (const AString & a_Message) override;
- virtual void SendChat (const cCompositeChat & a_Message) override;
- virtual void SendChatAboveActionBar (const AString & a_Message) override;
- virtual void SendChatAboveActionBar (const cCompositeChat & a_Message) override;
- virtual void SendChatSystem (const AString & a_Message) override;
- virtual void SendChatSystem (const cCompositeChat & a_Message) override;
- virtual void SendChatType (const AString & a_Message, eChatType type) override;
- virtual void SendChatType (const cCompositeChat & a_Message, eChatType type) override;
+ virtual void SendChat (const AString & a_Message, eChatType a_Type) override;
+ virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
virtual void SendDestroyEntity (const cEntity & a_Entity) override;
diff --git a/src/Root.cpp b/src/Root.cpp
index dc90671fb..13166d883 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -22,6 +22,7 @@
#include "SettingsRepositoryInterface.h"
#include "OverridesSettingsRepository.h"
#include "SelfTests.h"
+#include "Logger.h"
#include <iostream>
@@ -107,10 +108,15 @@ void cRoot::Start(std::unique_ptr<cSettingsRepositoryInterface> a_OverridesRepo)
EnableMenuItem(ConsoleMenu, SC_CLOSE, MF_GRAYED); // Disable close button when starting up; it causes problems with our CTRL-CLOSE handling
#endif
- cLogger::cListener * consoleLogListener = MakeConsoleListener(m_RunAsService);
- cLogger::cListener * fileLogListener = new cFileListener();
- cLogger::GetInstance().AttachListener(consoleLogListener);
- cLogger::GetInstance().AttachListener(fileLogListener);
+ auto consoleLogListener = MakeConsoleListener(m_RunAsService);
+ auto consoleAttachment = cLogger::GetInstance().AttachListener(std::move(consoleLogListener));
+ auto fileLogListenerRet = MakeFileListener();
+ if (!fileLogListenerRet.first)
+ {
+ LOGERROR("Failed to open log file, aborting");
+ return;
+ }
+ auto fileAttachment = cLogger::GetInstance().AttachListener(std::move(fileLogListenerRet.second));
LOG("--- Started Log ---");
@@ -317,11 +323,6 @@ void cRoot::Start(std::unique_ptr<cSettingsRepositoryInterface> a_OverridesRepo)
LOG("Shutdown successful - restarting...");
}
LOG("--- Stopped Log ---");
-
- cLogger::GetInstance().DetachListener(consoleLogListener);
- delete consoleLogListener;
- cLogger::GetInstance().DetachListener(fileLogListener);
- delete fileLogListener;
}
diff --git a/src/World.cpp b/src/World.cpp
index f929e2d1a..eb96eb57a 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -255,8 +255,6 @@ int cWorld::GetDefaultWeatherInterval(eWeather a_Weather)
return 2400 + (m_TickRand.randInt() % 4800); // 2 - 6 minutes
}
}
- LOGWARNING("%s: Missing default weather interval for weather %d.", __FUNCTION__, a_Weather);
- return -1;
}
@@ -646,10 +644,6 @@ eWeather cWorld::ChooseNewWeather()
return ((m_TickRand.randInt() % 256) < 32) ? eWeather_ThunderStorm : eWeather_Sunny;
}
}
-
- LOGWARNING("Unknown current weather: %d. Setting sunny.", m_Weather);
- ASSERT(!"Unknown weather");
- return eWeather_Sunny;
}
diff --git a/src/main.cpp b/src/main.cpp
index bc2439616..b9c3ae0bc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,6 +14,7 @@
#include "OSSupport/NetworkSingleton.h"
#include "BuildInfo.h"
+#include "Logger.h"
#include "MemorySettingsRepository.h"
@@ -471,6 +472,10 @@ int main(int argc, char **argv)
#endif // SIGABRT_COMPAT
#endif
+
+ #ifdef __unix__
+ std::signal(SIGPIPE, SIG_IGN);
+ #endif
#ifdef _WIN32
if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE))