diff options
author | Howaner <franzi.moos@googlemail.com> | 2015-03-10 20:05:46 +0100 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2015-03-10 20:05:46 +0100 |
commit | ab420f6cfc8519fb2ec0caa7fb242517244ffcea (patch) | |
tree | c31c3538db081516d81959ed8ad00259175441a9 /src/Protocol | |
parent | Changed return type from AbsorbWater() to void. (diff) | |
parent | Fixed client kick/crash if many block changes happend (diff) | |
download | cuberite-Sponge.tar cuberite-Sponge.tar.gz cuberite-Sponge.tar.bz2 cuberite-Sponge.tar.lz cuberite-Sponge.tar.xz cuberite-Sponge.tar.zst cuberite-Sponge.zip |
Diffstat (limited to 'src/Protocol')
-rw-r--r-- | src/Protocol/Protocol17x.cpp | 11 | ||||
-rw-r--r-- | src/Protocol/Protocol18x.cpp | 51 |
2 files changed, 39 insertions, 23 deletions
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 169367949..f78c2e54b 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -679,8 +679,8 @@ void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) { - ASSERT((it->GetPixelX() >= 0) && (it->GetPixelX() < 256)); - ASSERT((it->GetPixelZ() >= 0) && (it->GetPixelZ() < 256)); + ASSERT(it->GetPixelX() < 256); + ASSERT(it->GetPixelZ() < 256); Pkt.WriteByte(static_cast<Byte>((it->GetType() << 4) | static_cast<Byte>(it->GetRot() & 0xf))); Pkt.WriteByte(static_cast<Byte>(it->GetPixelX())); Pkt.WriteByte(static_cast<Byte>(it->GetPixelZ())); @@ -694,7 +694,7 @@ void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor void cProtocol172::SendMapInfo(int a_ID, unsigned int a_Scale) { ASSERT(m_State == 3); // In game mode? - ASSERT((a_Scale >= 0) && (a_Scale < 256)); + ASSERT(a_Scale < 256); cPacketizer Pkt(*this, 0x34); Pkt.WriteVarInt(static_cast<UInt32>(a_ID)); @@ -1757,7 +1757,10 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer) { short EncKeyLength, EncNonceLength; - a_ByteBuffer.ReadBEShort(EncKeyLength); + if (!a_ByteBuffer.ReadBEShort(EncKeyLength)) + { + return; + } if ((EncKeyLength < 0) || (EncKeyLength > MAX_ENC_LEN)) { LOGD("Invalid Encryption Key length: %d. Kicking client.", EncKeyLength); diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 3c4e049bd..22280f800 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -108,8 +108,17 @@ cProtocol180::cProtocol180(cClientHandle * a_Client, const AString & a_ServerAdd { static int sCounter = 0; cFile::CreateFolder("CommLogs"); - AString FileName = Printf("CommLogs/%x_%d__%s.log", (unsigned)time(nullptr), sCounter++, a_Client->GetIPString().c_str()); - m_CommLogFile.Open(FileName, cFile::fmWrite); + AString IP(a_Client->GetIPString()); + ReplaceString(IP, ":", "_"); + AString FileName = Printf("CommLogs/%x_%d__%s.log", + static_cast<unsigned>(time(nullptr)), + sCounter++, + IP.c_str() + ); + if (!m_CommLogFile.Open(FileName, cFile::fmWrite)) + { + LOG("Cannot log communication to file, the log file \"%s\" cannot be opened for writing.", FileName.c_str()); + } } } @@ -377,7 +386,7 @@ void cProtocol180::SendEntityLook(const cEntity & a_Entity) Pkt.WriteVarInt(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetYaw()); Pkt.WriteByteAngle(a_Entity.GetPitch()); - Pkt.WriteBool(true); // TODO: IsOnGround() on entities + Pkt.WriteBool(a_Entity.IsOnGround()); } @@ -420,7 +429,7 @@ void cProtocol180::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char Pkt.WriteByte(a_RelX); Pkt.WriteByte(a_RelY); Pkt.WriteByte(a_RelZ); - Pkt.WriteBool(true); // TODO: IsOnGround() on entities + Pkt.WriteBool(a_Entity.IsOnGround()); } @@ -438,7 +447,7 @@ void cProtocol180::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, Pkt.WriteByte(a_RelZ); Pkt.WriteByteAngle(a_Entity.GetYaw()); Pkt.WriteByteAngle(a_Entity.GetPitch()); - Pkt.WriteBool(true); // TODO: IsOnGround() on entities + Pkt.WriteBool(a_Entity.IsOnGround()); } @@ -865,11 +874,15 @@ void cProtocol180::SendPlayerListUpdatePing(const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x38); // Playerlist Item packet - Pkt.WriteVarInt(2); - Pkt.WriteVarInt(1); - Pkt.WriteUUID(a_Player.GetUUID()); - Pkt.WriteVarInt((UInt32)a_Player.GetClientHandle()->GetPing()); + auto ClientHandle = a_Player.GetClientHandlePtr(); + if (ClientHandle != nullptr) + { + cPacketizer Pkt(*this, 0x38); // Playerlist Item packet + Pkt.WriteVarInt(2); + Pkt.WriteVarInt(1); + Pkt.WriteUUID(a_Player.GetUUID()); + Pkt.WriteVarInt(static_cast<UInt32>(ClientHandle->GetPing())); + } } @@ -938,7 +951,7 @@ void cProtocol180::SendPlayerMoveLook(void) Pkt.WriteDouble(Player->GetPosX()); // The "+ 0.001" is there because otherwise the player falls through the block they were standing on. - Pkt.WriteDouble(Player->GetStance() + 0.001); + Pkt.WriteDouble(Player->GetPosY() + 0.001); Pkt.WriteDouble(Player->GetPosZ()); Pkt.WriteFloat((float)Player->GetYaw()); @@ -967,7 +980,7 @@ void cProtocol180::SendPlayerSpawn(const cPlayer & a_Player) Pkt.WriteVarInt(a_Player.GetUniqueID()); Pkt.WriteUUID(cMojangAPI::MakeUUIDShort(a_Player.GetUUID())); Pkt.WriteFPInt(a_Player.GetPosX()); - Pkt.WriteFPInt(a_Player.GetPosY()); + Pkt.WriteFPInt(a_Player.GetPosY() + 0.001); // The "+ 0.001" is there because otherwise the player falls through the block they were standing on. Pkt.WriteFPInt(a_Player.GetPosZ()); Pkt.WriteByteAngle(a_Player.GetYaw()); Pkt.WriteByteAngle(a_Player.GetPitch()); @@ -1296,7 +1309,7 @@ void cProtocol180::SendTeleportEntity(const cEntity & a_Entity) Pkt.WriteFPInt(a_Entity.GetPosZ()); Pkt.WriteByteAngle(a_Entity.GetYaw()); Pkt.WriteByteAngle(a_Entity.GetPitch()); - Pkt.WriteBool(true); // TODO: IsOnGrond() on entities + Pkt.WriteBool(a_Entity.IsOnGround()); } @@ -1659,7 +1672,7 @@ void cProtocol180::FixItemFramePositions(int a_ObjectData, double & a_PosX, doub void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) { // Write the incoming data into the comm log file: - if (g_ShouldLogCommIn) + if (g_ShouldLogCommIn && m_CommLogFile.IsOpen()) { if (m_ReceivedData.GetReadableSpace() > 0) { @@ -1764,7 +1777,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) bb.Write("\0", 1); // Log the packet info into the comm log file: - if (g_ShouldLogCommIn) + if (g_ShouldLogCommIn && m_CommLogFile.IsOpen()) { AString PacketData; bb.ReadAll(PacketData); @@ -1796,7 +1809,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) #endif // _DEBUG // Put a message in the comm log: - if (g_ShouldLogCommIn) + if (g_ShouldLogCommIn && m_CommLogFile.IsOpen()) { m_CommLogFile.Printf("^^^^^^ Unhandled packet ^^^^^^\n\n\n"); } @@ -1813,7 +1826,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) ); // Put a message in the comm log: - if (g_ShouldLogCommIn) + if (g_ShouldLogCommIn && m_CommLogFile.IsOpen()) { m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got " SIZE_T_FMT " left) ^^^^^^\n\n\n", 1, bb.GetReadableSpace() @@ -1827,7 +1840,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) } // for (ever) // Log any leftover bytes into the logfile: - if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0)) + if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0) && m_CommLogFile.IsOpen()) { AString AllData; size_t OldReadableSpace = m_ReceivedData.GetReadableSpace(); @@ -2798,7 +2811,7 @@ cProtocol180::cPacketizer::~cPacketizer() } // Log the comm into logfile: - if (g_ShouldLogCommOut) + if (g_ShouldLogCommOut && m_Protocol.m_CommLogFile.IsOpen()) { AString Hex; ASSERT(PacketData.size() > 0); |