commit
f36a00c603
|
@ -100,13 +100,11 @@
|
|||
CLIENTENCRYPTSEND(ToClient.data(), ToClient.size()); \
|
||||
break; \
|
||||
} \
|
||||
/* case csWaitingForEncryption: \
|
||||
case csWaitingForEncryption: \
|
||||
{ \
|
||||
Log("Waiting for client encryption, queued %u bytes", ToClient.size()); \
|
||||
m_ClientEncryptionBuffer.append(ToClient.data(), ToClient.size()); \
|
||||
break; \
|
||||
} \
|
||||
*/ \
|
||||
\
|
||||
} \
|
||||
DebugSleep(50); \
|
||||
}
|
||||
|
@ -141,8 +139,14 @@ typedef unsigned char Byte;
|
|||
|
||||
|
||||
|
||||
// fwd declarations, to avoid clang warnings:
|
||||
AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor = 32);
|
||||
|
||||
AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor = 32)
|
||||
|
||||
|
||||
|
||||
|
||||
AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor)
|
||||
{
|
||||
return Printf("<%d, %d, %d> ~ {%.02f, %.02f, %.02f}",
|
||||
a_X, a_Y, a_Z,
|
||||
|
@ -298,7 +302,7 @@ void cConnection::Log(const char * a_Format, ...)
|
|||
|
||||
|
||||
|
||||
void cConnection::DataLog(const void * a_Data, int a_Size, const char * a_Format, ...)
|
||||
void cConnection::DataLog(const void * a_Data, size_t a_Size, const char * a_Format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, a_Format);
|
||||
|
@ -359,14 +363,14 @@ bool cConnection::ConnectToServer(void)
|
|||
bool cConnection::RelayFromServer(void)
|
||||
{
|
||||
char Buffer[64 KiB];
|
||||
int res = recv(m_ServerSocket, Buffer, sizeof(Buffer), 0);
|
||||
int res = static_cast<int>(recv(m_ServerSocket, Buffer, sizeof(Buffer), 0)); // recv returns int on windows, ssize_t on linux
|
||||
if (res <= 0)
|
||||
{
|
||||
Log("Server closed the socket: %d; %d; aborting connection", res, SocketError);
|
||||
return false;
|
||||
}
|
||||
|
||||
DataLog(Buffer, res, "Received %d bytes from the SERVER", res);
|
||||
DataLog(Buffer, static_cast<size_t>(res), "Received %d bytes from the SERVER", res);
|
||||
|
||||
switch (m_ServerState)
|
||||
{
|
||||
|
@ -377,15 +381,15 @@ bool cConnection::RelayFromServer(void)
|
|||
}
|
||||
case csEncryptedUnderstood:
|
||||
{
|
||||
m_ServerDecryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res);
|
||||
DataLog(Buffer, res, "Decrypted %d bytes from the SERVER", res);
|
||||
m_ServerDecryptor.ProcessData(reinterpret_cast<Byte *>(Buffer), reinterpret_cast<Byte *>(Buffer), static_cast<size_t>(res));
|
||||
DataLog(Buffer, static_cast<size_t>(res), "Decrypted %d bytes from the SERVER", res);
|
||||
return DecodeServersPackets(Buffer, res);
|
||||
}
|
||||
case csEncryptedUnknown:
|
||||
{
|
||||
m_ServerDecryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res);
|
||||
DataLog(Buffer, res, "Decrypted %d bytes from the SERVER", res);
|
||||
return CLIENTSEND(Buffer, res);
|
||||
m_ServerDecryptor.ProcessData(reinterpret_cast<Byte *>(Buffer), reinterpret_cast<Byte *>(Buffer), static_cast<size_t>(res));
|
||||
DataLog(Buffer, static_cast<size_t>(res), "Decrypted %d bytes from the SERVER", res);
|
||||
return CLIENTSEND(Buffer, static_cast<size_t>(res));
|
||||
}
|
||||
}
|
||||
ASSERT(!"Unhandled server state while relaying from server");
|
||||
|
@ -399,14 +403,14 @@ bool cConnection::RelayFromServer(void)
|
|||
bool cConnection::RelayFromClient(void)
|
||||
{
|
||||
char Buffer[64 KiB];
|
||||
int res = recv(m_ClientSocket, Buffer, sizeof(Buffer), 0);
|
||||
int res = static_cast<int>(recv(m_ClientSocket, Buffer, sizeof(Buffer), 0)); // recv returns int on Windows, ssize_t on Linux
|
||||
if (res <= 0)
|
||||
{
|
||||
Log("Client closed the socket: %d; %d; aborting connection", res, SocketError);
|
||||
return false;
|
||||
}
|
||||
|
||||
DataLog(Buffer, res, "Received %d bytes from the CLIENT", res);
|
||||
DataLog(Buffer, static_cast<size_t>(res), "Received %d bytes from the CLIENT", res);
|
||||
|
||||
switch (m_ClientState)
|
||||
{
|
||||
|
@ -421,9 +425,9 @@ bool cConnection::RelayFromClient(void)
|
|||
}
|
||||
case csEncryptedUnknown:
|
||||
{
|
||||
DataLog(Buffer, res, "Decrypted %d bytes from the CLIENT", res);
|
||||
m_ServerEncryptor.ProcessData((Byte *)Buffer, (Byte *)Buffer, res);
|
||||
return SERVERSEND(Buffer, res);
|
||||
DataLog(Buffer, static_cast<size_t>(res), "Decrypted %d bytes from the CLIENT", res);
|
||||
m_ServerEncryptor.ProcessData(reinterpret_cast<Byte *>(Buffer), reinterpret_cast<Byte *>(Buffer), static_cast<size_t>(res));
|
||||
return SERVERSEND(Buffer, static_cast<size_t>(res));
|
||||
}
|
||||
}
|
||||
ASSERT(!"Unhandled server state while relaying from client");
|
||||
|
@ -446,9 +450,9 @@ double cConnection::GetRelativeTime(void)
|
|||
|
||||
bool cConnection::SendData(SOCKET a_Socket, const char * a_Data, size_t a_Size, const char * a_Peer)
|
||||
{
|
||||
DataLog(a_Data, a_Size, "Sending data to %s, %u bytes", a_Peer, (unsigned)a_Size);
|
||||
DataLog(a_Data, a_Size, "Sending data to %s, %u bytes", a_Peer, static_cast<unsigned>(a_Size));
|
||||
|
||||
int res = send(a_Socket, a_Data, (int)a_Size, 0);
|
||||
int res = static_cast<int>(send(a_Socket, a_Data, a_Size, 0)); // Windows uses int for a_Size, Linux uses size_t; but Windows doesn't complain. Return type is int on Windows and ssize_t on Linux
|
||||
if (res <= 0)
|
||||
{
|
||||
Log("%s closed the socket: %d, %d; aborting connection", a_Peer, res, SocketError);
|
||||
|
@ -511,7 +515,7 @@ bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Enc
|
|||
|
||||
bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size)
|
||||
{
|
||||
if (!m_ClientBuffer.Write(a_Data, a_Size))
|
||||
if (!m_ClientBuffer.Write(a_Data, static_cast<size_t>(a_Size)))
|
||||
{
|
||||
Log("Too much queued data for the server, aborting connection");
|
||||
return false;
|
||||
|
@ -529,10 +533,12 @@ bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size)
|
|||
break;
|
||||
}
|
||||
UInt32 PacketType, PacketReadSoFar;
|
||||
PacketReadSoFar = m_ClientBuffer.GetReadableSpace();
|
||||
PacketReadSoFar = static_cast<UInt32>(m_ClientBuffer.GetReadableSpace());
|
||||
VERIFY(m_ClientBuffer.ReadVarInt(PacketType));
|
||||
PacketReadSoFar -= m_ClientBuffer.GetReadableSpace();
|
||||
Log("Decoding client's packets, there are now %d bytes in the queue; next packet is 0x%0x, %u bytes long", m_ClientBuffer.GetReadableSpace(), PacketType, PacketLen);
|
||||
Log("Decoding client's packets, there are now %u bytes in the queue; next packet is 0x%02x, %u bytes long",
|
||||
static_cast<unsigned>(m_ClientBuffer.GetReadableSpace()), PacketType, PacketLen
|
||||
);
|
||||
switch (m_ClientProtocolState)
|
||||
{
|
||||
case -1:
|
||||
|
@ -619,7 +625,7 @@ bool cConnection::DecodeClientsPackets(const char * a_Data, int a_Size)
|
|||
|
||||
bool cConnection::DecodeServersPackets(const char * a_Data, int a_Size)
|
||||
{
|
||||
if (!m_ServerBuffer.Write(a_Data, a_Size))
|
||||
if (!m_ServerBuffer.Write(a_Data, static_cast<size_t>(a_Size)))
|
||||
{
|
||||
Log("Too much queued data for the client, aborting connection");
|
||||
return false;
|
||||
|
@ -655,7 +661,7 @@ bool cConnection::DecodeServersPackets(const char * a_Data, int a_Size)
|
|||
break;
|
||||
}
|
||||
UInt32 PacketType, PacketReadSoFar;
|
||||
PacketReadSoFar = m_ServerBuffer.GetReadableSpace();
|
||||
PacketReadSoFar = static_cast<UInt32>(m_ServerBuffer.GetReadableSpace());
|
||||
VERIFY(m_ServerBuffer.ReadVarInt(PacketType));
|
||||
PacketReadSoFar -= m_ServerBuffer.GetReadableSpace();
|
||||
Log("Decoding server's packets, there are now %d bytes in the queue; next packet is 0x%0x, %u bytes long", m_ServerBuffer.GetReadableSpace(), PacketType, PacketLen);
|
||||
|
@ -1111,7 +1117,7 @@ bool cConnection::HandleClientPlayerPositionLook(void)
|
|||
bool cConnection::HandleClientPluginMessage(void)
|
||||
{
|
||||
HANDLE_CLIENT_PACKET_READ(ReadVarUTF8String, AString, ChannelName);
|
||||
HANDLE_CLIENT_PACKET_READ(ReadBEShort, short, Length);
|
||||
HANDLE_CLIENT_PACKET_READ(ReadBEUInt16, UInt16, Length);
|
||||
AString Data;
|
||||
if (!m_ClientBuffer.ReadString(Data, Length))
|
||||
{
|
||||
|
@ -1119,7 +1125,7 @@ bool cConnection::HandleClientPluginMessage(void)
|
|||
}
|
||||
Log("Received a PACKET_PLUGIN_MESSAGE from the client");
|
||||
Log(" ChannelName = \"%s\"", ChannelName.c_str());
|
||||
DataLog(Data.data(), Length, " Data: %d bytes", Length);
|
||||
DataLog(Data.data(), Length, " Data: %u bytes", Length);
|
||||
COPY_TO_SERVER();
|
||||
return true;
|
||||
}
|
||||
|
@ -1288,13 +1294,13 @@ bool cConnection::HandleServerLoginEncryptionKeyRequest(void)
|
|||
{
|
||||
// Read the packet from the server:
|
||||
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, ServerID);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, PublicKeyLength);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, PublicKeyLength);
|
||||
AString PublicKey;
|
||||
if (!m_ServerBuffer.ReadString(PublicKey, PublicKeyLength))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, NonceLength);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, NonceLength);
|
||||
AString Nonce;
|
||||
if (!m_ServerBuffer.ReadString(Nonce, NonceLength))
|
||||
{
|
||||
|
@ -1464,12 +1470,12 @@ bool cConnection::HandleServerCompass(void)
|
|||
bool cConnection::HandleServerDestroyEntities(void)
|
||||
{
|
||||
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, NumEntities);
|
||||
if (!m_ServerBuffer.SkipRead((int)NumEntities * 4))
|
||||
if (!m_ServerBuffer.SkipRead(static_cast<size_t>(NumEntities) * 4))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Log("Received PACKET_DESTROY_ENTITIES from the server:");
|
||||
Log(" NumEntities = %d", NumEntities);
|
||||
Log(" NumEntities = %u", NumEntities);
|
||||
COPY_TO_CLIENT();
|
||||
return true;
|
||||
}
|
||||
|
@ -1690,15 +1696,15 @@ bool cConnection::HandleServerEntityVelocity(void)
|
|||
|
||||
bool cConnection::HandleServerExplosion(void)
|
||||
{
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosX);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosY);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosZ);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Force);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, NumRecords);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosX);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosY);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, PosZ);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEFloat, float, Force);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, NumRecords);
|
||||
std::vector<sCoords> Records;
|
||||
Records.reserve(NumRecords);
|
||||
int PosXI = (int)PosX, PosYI = (int)PosY, PosZI = (int)PosZ;
|
||||
for (int i = 0; i < NumRecords; i++)
|
||||
for (UInt32 i = 0; i < NumRecords; i++)
|
||||
{
|
||||
HANDLE_SERVER_PACKET_READ(ReadChar, char, rx);
|
||||
HANDLE_SERVER_PACKET_READ(ReadChar, char, ry);
|
||||
|
@ -1711,10 +1717,10 @@ bool cConnection::HandleServerExplosion(void)
|
|||
Log("Received a PACKET_EXPLOSION from the server:");
|
||||
Log(" Pos = {%.02f, %.02f, %.02f}", PosX, PosY, PosZ);
|
||||
Log(" Force = %.02f", Force);
|
||||
Log(" NumRecords = %d", NumRecords);
|
||||
for (int i = 0; i < NumRecords; i++)
|
||||
Log(" NumRecords = %u", NumRecords);
|
||||
for (UInt32 i = 0; i < NumRecords; i++)
|
||||
{
|
||||
Log(" Records[%d] = {%d, %d, %d}", i, Records[i].x, Records[i].y, Records[i].z);
|
||||
Log(" Records[%u] = {%d, %d, %d}", i, Records[i].x, Records[i].y, Records[i].z);
|
||||
}
|
||||
Log(" Player motion = <%.02f, %.02f, %.02f>", PlayerMotionX, PlayerMotionY, PlayerMotionZ);
|
||||
COPY_TO_CLIENT();
|
||||
|
@ -1825,8 +1831,8 @@ bool cConnection::HandleServerKick(void)
|
|||
Reason.append(Split[5]);
|
||||
AString ReasonBE16 = UTF8ToRawBEUTF16(Reason.data(), Reason.size());
|
||||
AString PacketStart("\xff");
|
||||
PacketStart.push_back((ReasonBE16.size() / 2) / 256);
|
||||
PacketStart.push_back((ReasonBE16.size() / 2) % 256);
|
||||
PacketStart.push_back(static_cast<char>((ReasonBE16.size() / 2) / 256));
|
||||
PacketStart.push_back(static_cast<char>((ReasonBE16.size() / 2) % 256));
|
||||
CLIENTSEND(PacketStart.data(), PacketStart.size());
|
||||
CLIENTSEND(ReasonBE16.data(), ReasonBE16.size());
|
||||
return true;
|
||||
|
@ -1850,12 +1856,12 @@ bool cConnection::HandleServerKick(void)
|
|||
|
||||
bool cConnection::HandleServerMapChunk(void)
|
||||
{
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ);
|
||||
HANDLE_SERVER_PACKET_READ(ReadChar, char, IsContiguous);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, PrimaryBitmap);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, AdditionalBitmap);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, CompressedSize);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ);
|
||||
HANDLE_SERVER_PACKET_READ(ReadChar, char, IsContiguous);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, PrimaryBitmap);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, AdditionalBitmap);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, CompressedSize);
|
||||
AString CompressedData;
|
||||
if (!m_ServerBuffer.ReadString(CompressedData, CompressedSize))
|
||||
{
|
||||
|
@ -1863,7 +1869,7 @@ bool cConnection::HandleServerMapChunk(void)
|
|||
}
|
||||
Log("Received a PACKET_MAP_CHUNK from the server:");
|
||||
Log(" ChunkPos = [%d, %d]", ChunkX, ChunkZ);
|
||||
Log(" Compressed size = %d (0x%x)", CompressedSize, CompressedSize);
|
||||
Log(" Compressed size = %u (0x%x)", CompressedSize, CompressedSize);
|
||||
|
||||
// TODO: Save the compressed data into a file for later analysis
|
||||
|
||||
|
@ -1877,9 +1883,9 @@ bool cConnection::HandleServerMapChunk(void)
|
|||
|
||||
bool cConnection::HandleServerMapChunkBulk(void)
|
||||
{
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, ChunkCount);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, CompressedSize);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBool, bool, IsSkyLightSent);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, ChunkCount);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, CompressedSize);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBool, bool, IsSkyLightSent);
|
||||
AString CompressedData;
|
||||
if (!m_ServerBuffer.ReadString(CompressedData, CompressedSize))
|
||||
{
|
||||
|
@ -1901,8 +1907,8 @@ bool cConnection::HandleServerMapChunkBulk(void)
|
|||
}
|
||||
|
||||
Log("Received a PACKET_MAP_CHUNK_BULK from the server:");
|
||||
Log(" ChunkCount = %d", ChunkCount);
|
||||
Log(" Compressed size = %d (0x%x)", CompressedSize, CompressedSize);
|
||||
Log(" ChunkCount = %u", ChunkCount);
|
||||
Log(" Compressed size = %u (0x%x)", CompressedSize, CompressedSize);
|
||||
Log(" IsSkyLightSent = %s", IsSkyLightSent ? "true" : "false");
|
||||
|
||||
// Log individual chunk coords:
|
||||
|
@ -1926,10 +1932,10 @@ bool cConnection::HandleServerMapChunkBulk(void)
|
|||
|
||||
bool cConnection::HandleServerMultiBlockChange(void)
|
||||
{
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, NumBlocks);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, DataSize);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkX);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, ChunkZ);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, NumBlocks);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, DataSize);
|
||||
AString BlockChangeData;
|
||||
if (!m_ServerBuffer.ReadString(BlockChangeData, DataSize))
|
||||
{
|
||||
|
@ -1937,7 +1943,7 @@ bool cConnection::HandleServerMultiBlockChange(void)
|
|||
}
|
||||
Log("Received a PACKET_MULTI_BLOCK_CHANGE packet from the server:");
|
||||
Log(" Chunk = [%d, %d]", ChunkX, ChunkZ);
|
||||
Log(" NumBlocks = %d", NumBlocks);
|
||||
Log(" NumBlocks = %u", NumBlocks);
|
||||
COPY_TO_CLIENT();
|
||||
return true;
|
||||
}
|
||||
|
@ -2038,7 +2044,7 @@ bool cConnection::HandleServerPlayerPositionLook(void)
|
|||
bool cConnection::HandleServerPluginMessage(void)
|
||||
{
|
||||
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, ChannelName);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, Length);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, Length);
|
||||
AString Data;
|
||||
if (!m_ServerBuffer.ReadString(Data, Length))
|
||||
{
|
||||
|
@ -2046,7 +2052,7 @@ bool cConnection::HandleServerPluginMessage(void)
|
|||
}
|
||||
Log("Received a PACKET_PLUGIN_MESSAGE from the server");
|
||||
Log(" ChannelName = \"%s\"", ChannelName.c_str());
|
||||
DataLog(Data.data(), Length, " Data: %d bytes", Length);
|
||||
DataLog(Data.data(), Length, " Data: %u bytes", Length);
|
||||
COPY_TO_CLIENT();
|
||||
return true;
|
||||
}
|
||||
|
@ -2533,11 +2539,11 @@ bool cConnection::HandleServerUpdateSign(void)
|
|||
|
||||
bool cConnection::HandleServerUpdateTileEntity(void)
|
||||
{
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockX);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, BlockY);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockZ);
|
||||
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Action);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, DataLength);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockX);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, BlockY);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, BlockZ);
|
||||
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Action);
|
||||
HANDLE_SERVER_PACKET_READ(ReadBEUInt16, UInt16, DataLength);
|
||||
|
||||
AString Data;
|
||||
if ((DataLength > 0) && !m_ServerBuffer.ReadString(Data, DataLength))
|
||||
|
@ -2551,7 +2557,7 @@ bool cConnection::HandleServerUpdateTileEntity(void)
|
|||
|
||||
// Save metadata to a file:
|
||||
AString fnam;
|
||||
Printf(fnam, "%s_item_%08x.nbt", m_LogNameBase.c_str(), m_ItemIdx++);
|
||||
Printf(fnam, "%s_tile_%08x.nbt", m_LogNameBase.c_str(), m_ItemIdx++);
|
||||
FILE * f = fopen(fnam.c_str(), "wb");
|
||||
if (f != NULL)
|
||||
{
|
||||
|
@ -2689,10 +2695,10 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc)
|
|||
}
|
||||
char ItemCount;
|
||||
short ItemDamage;
|
||||
short MetadataLength;
|
||||
UInt16 MetadataLength;
|
||||
a_Buffer.ReadChar(ItemCount); // We already know we can read these bytes - we checked before.
|
||||
a_Buffer.ReadBEShort(ItemDamage);
|
||||
a_Buffer.ReadBEShort(MetadataLength);
|
||||
a_Buffer.ReadBEUInt16(MetadataLength);
|
||||
Printf(a_ItemDesc, "%d:%d * %d", ItemType, ItemDamage, ItemCount);
|
||||
if (MetadataLength <= 0)
|
||||
{
|
||||
|
@ -2700,13 +2706,13 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc)
|
|||
}
|
||||
AString Metadata;
|
||||
Metadata.resize(MetadataLength);
|
||||
if (!a_Buffer.ReadBuf((void *)Metadata.data(), MetadataLength))
|
||||
if (!a_Buffer.ReadBuf(const_cast<char *>(Metadata.data()), MetadataLength))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
AString MetaHex;
|
||||
CreateHexDump(MetaHex, Metadata.data(), Metadata.size(), 16);
|
||||
AppendPrintf(a_ItemDesc, "; %d bytes of meta:\n%s", MetadataLength, MetaHex.c_str());
|
||||
AppendPrintf(a_ItemDesc, "; %u bytes of meta:\n%s", MetadataLength, MetaHex.c_str());
|
||||
|
||||
// Save metadata to a file:
|
||||
AString fnam;
|
||||
|
@ -2728,17 +2734,19 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc)
|
|||
|
||||
bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
|
||||
{
|
||||
char x;
|
||||
if (!a_Buffer.ReadChar(x))
|
||||
Byte x;
|
||||
if (!a_Buffer.ReadByte(x))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
a_Metadata.push_back(x);
|
||||
a_Metadata.push_back(static_cast<char>(x));
|
||||
while (x != 0x7f)
|
||||
{
|
||||
// int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index
|
||||
int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type
|
||||
int Length = 0;
|
||||
// int Index = static_cast<unsigned>(x) & 0x1f; // Lower 5 bits = index
|
||||
int Type = static_cast<unsigned>(x) >> 5; // Upper 3 bits = type
|
||||
|
||||
// Get the length of the data for this item:
|
||||
UInt32 Length = 0;
|
||||
switch (Type)
|
||||
{
|
||||
case 0: Length = 1; break; // Byte
|
||||
|
@ -2748,12 +2756,12 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
|
|||
case 4: // UTF-8 string with VarInt length
|
||||
{
|
||||
UInt32 Len;
|
||||
int rs = a_Buffer.GetReadableSpace();
|
||||
int rs = static_cast<int>(a_Buffer.GetReadableSpace());
|
||||
if (!a_Buffer.ReadVarInt(Len))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
rs = rs - a_Buffer.GetReadableSpace();
|
||||
rs = rs - static_cast<int>(a_Buffer.GetReadableSpace());
|
||||
cByteBuffer LenBuf(8);
|
||||
LenBuf.WriteVarInt(Len);
|
||||
AString VarLen;
|
||||
|
@ -2762,18 +2770,18 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
|
|||
Length = Len;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
case 5: // Item, in "slot" format
|
||||
{
|
||||
int Before = a_Buffer.GetReadableSpace();
|
||||
size_t Before = a_Buffer.GetReadableSpace();
|
||||
AString ItemDesc;
|
||||
if (!ParseSlot(a_Buffer, ItemDesc))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int After = a_Buffer.GetReadableSpace();
|
||||
size_t After = a_Buffer.GetReadableSpace();
|
||||
a_Buffer.ResetRead();
|
||||
a_Buffer.SkipRead(a_Buffer.GetReadableSpace() - Before);
|
||||
Length = Before - After;
|
||||
Length = static_cast<UInt32>(Before - After);
|
||||
break;
|
||||
}
|
||||
case 6: Length = 12; break; // 3 * int
|
||||
|
@ -2784,17 +2792,19 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
|
|||
break;
|
||||
}
|
||||
} // switch (Type)
|
||||
|
||||
// Read the data in this item:
|
||||
AString data;
|
||||
if (!a_Buffer.ReadString(data, Length))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
a_Metadata.append(data);
|
||||
if (!a_Buffer.ReadChar(x))
|
||||
if (!a_Buffer.ReadByte(x))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
a_Metadata.push_back(x);
|
||||
a_Metadata.push_back(static_cast<char>(x));
|
||||
} // while (x != 0x7f)
|
||||
return true;
|
||||
}
|
||||
|
@ -2806,62 +2816,62 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
|
|||
void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount)
|
||||
{
|
||||
AString Indent(a_IndentCount, ' ');
|
||||
int pos = 0;
|
||||
size_t pos = 0;
|
||||
while (a_Metadata[pos] != 0x7f)
|
||||
{
|
||||
int Index = ((unsigned)((unsigned char)a_Metadata[pos])) & 0x1f; // Lower 5 bits = index
|
||||
int Type = ((unsigned)((unsigned char)a_Metadata[pos])) >> 5; // Upper 3 bits = type
|
||||
unsigned Index = static_cast<unsigned>(static_cast<unsigned char>(a_Metadata[pos])) & 0x1f; // Lower 5 bits = index
|
||||
unsigned Type = static_cast<unsigned>(static_cast<unsigned char>(a_Metadata[pos])) >> 5; // Upper 3 bits = type
|
||||
// int Length = 0;
|
||||
switch (Type)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Log("%sbyte[%d] = %d", Indent.c_str(), Index, a_Metadata[pos + 1]);
|
||||
Log("%sbyte[%u] = %d", Indent.c_str(), Index, a_Metadata[pos + 1]);
|
||||
pos += 1;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
Log("%sshort[%d] = %d", Indent.c_str(), Index, (a_Metadata[pos + 1] << 8) | a_Metadata[pos + 2]);
|
||||
Log("%sshort[%u] = %d", Indent.c_str(), Index, (a_Metadata[pos + 1] << 8) | a_Metadata[pos + 2]);
|
||||
pos += 2;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
Log("%sint[%d] = %d", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4]);
|
||||
Log("%sint[%u] = %d", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4]);
|
||||
pos += 4;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
Log("%sfloat[%d] = 0x%x", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4]);
|
||||
Log("%sfloat[%u] = 0x%x", Indent.c_str(), Index, (a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4]);
|
||||
pos += 4;
|
||||
break;
|
||||
}
|
||||
case 4: // UTF-8 string with VarInt length
|
||||
{
|
||||
cByteBuffer bb(10);
|
||||
int RestLen = (int)a_Metadata.size() - pos - 1;
|
||||
size_t RestLen = a_Metadata.size() - pos - 1;
|
||||
if (RestLen > 8)
|
||||
{
|
||||
RestLen = 8;
|
||||
}
|
||||
bb.Write(a_Metadata.data() + pos + 1, RestLen);
|
||||
UInt32 Length;
|
||||
int rs = bb.GetReadableSpace();
|
||||
size_t rs = bb.GetReadableSpace();
|
||||
if (!bb.ReadVarInt(Length))
|
||||
{
|
||||
Log("Invalid metadata value, was supposed to be a varint-prefixed string, but cannot read the varint");
|
||||
break;
|
||||
}
|
||||
rs = rs - bb.GetReadableSpace();
|
||||
Log("%sstring[%d] = \"%*s\"", Indent.c_str(), Index, Length, a_Metadata.c_str() + pos + rs + 1);
|
||||
Log("%sstring[%u] = \"%*s\"", Indent.c_str(), Index, Length, a_Metadata.c_str() + pos + rs + 1);
|
||||
pos += Length + rs + 2;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
int BytesLeft = a_Metadata.size() - pos - 1;
|
||||
size_t BytesLeft = a_Metadata.size() - pos - 1;
|
||||
cByteBuffer bb(BytesLeft);
|
||||
bb.Write(a_Metadata.data() + pos + 1, BytesLeft);
|
||||
AString ItemDesc;
|
||||
|
@ -2870,16 +2880,16 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount)
|
|||
ASSERT(!"Cannot parse item description from metadata");
|
||||
return;
|
||||
}
|
||||
// int After = bb.GetReadableSpace();
|
||||
int BytesConsumed = BytesLeft - bb.GetReadableSpace();
|
||||
// size_t After = bb.GetReadableSpace();
|
||||
size_t BytesConsumed = BytesLeft - bb.GetReadableSpace();
|
||||
|
||||
Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed);
|
||||
Log("%sslot[%u] = %s (%u bytes)", Indent.c_str(), Index, ItemDesc.c_str(), static_cast<unsigned>(BytesConsumed));
|
||||
pos += BytesConsumed;
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
Log("%spos[%d] = <%d, %d, %d>", Indent.c_str(), Index,
|
||||
Log("%spos[%u] = <%d, %d, %d>", Indent.c_str(), Index,
|
||||
(a_Metadata[pos + 1] << 24) | (a_Metadata[pos + 2] << 16) | (a_Metadata[pos + 3] << 8) | a_Metadata[pos + 4],
|
||||
(a_Metadata[pos + 5] << 24) | (a_Metadata[pos + 6] << 16) | (a_Metadata[pos + 7] << 8) | a_Metadata[pos + 8],
|
||||
(a_Metadata[pos + 9] << 24) | (a_Metadata[pos + 10] << 16) | (a_Metadata[pos + 11] << 8) | a_Metadata[pos + 12]
|
||||
|
@ -2938,7 +2948,7 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c
|
|||
DataLog(EncryptedSecret, sizeof(EncryptedSecret), "Encrypted secret (%u bytes)", (unsigned)sizeof(EncryptedSecret));
|
||||
DataLog(EncryptedNonce, sizeof(EncryptedNonce), "Encrypted nonce (%u bytes)", (unsigned)sizeof(EncryptedNonce));
|
||||
cByteBuffer Len(5);
|
||||
Len.WriteVarInt(ToServer.GetReadableSpace());
|
||||
Len.WriteVarInt(static_cast<UInt32>(ToServer.GetReadableSpace()));
|
||||
SERVERSEND(Len);
|
||||
SERVERSEND(ToServer);
|
||||
m_ServerState = csEncryptedUnderstood;
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
void Run(void);
|
||||
|
||||
void Log(const char * a_Format, ...);
|
||||
void DataLog(const void * a_Data, int a_Size, const char * a_Format, ...);
|
||||
void DataLog(const void * a_Data, size_t a_Size, const char * a_Format, ...);
|
||||
void LogFlush(void);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -344,12 +344,28 @@ bool cByteBuffer::ReadByte(unsigned char & a_Value)
|
|||
|
||||
|
||||
bool cByteBuffer::ReadBEShort(short & a_Value)
|
||||
{
|
||||
CHECK_THREAD
|
||||
CheckValid();
|
||||
NEEDBYTES(2);
|
||||
Int16 val;
|
||||
ReadBuf(&val, 2);
|
||||
val = ntohs(val);
|
||||
a_Value = *(reinterpret_cast<short *>(&val));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cByteBuffer::ReadBEUInt16(UInt16 & a_Value)
|
||||
{
|
||||
CHECK_THREAD
|
||||
CheckValid();
|
||||
NEEDBYTES(2);
|
||||
ReadBuf(&a_Value, 2);
|
||||
a_Value = (short)ntohs((u_short)a_Value);
|
||||
a_Value = ntohs(a_Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -371,6 +387,20 @@ bool cByteBuffer::ReadBEInt(int & a_Value)
|
|||
|
||||
|
||||
|
||||
bool cByteBuffer::ReadBEUInt32(UInt32 & a_Value)
|
||||
{
|
||||
CHECK_THREAD
|
||||
CheckValid();
|
||||
NEEDBYTES(4);
|
||||
ReadBuf(&a_Value, 4);
|
||||
a_Value = ntohl(a_Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cByteBuffer::ReadBEInt64(Int64 & a_Value)
|
||||
{
|
||||
CHECK_THREAD
|
||||
|
|
|
@ -55,7 +55,9 @@ public:
|
|||
bool ReadChar (char & a_Value);
|
||||
bool ReadByte (unsigned char & a_Value);
|
||||
bool ReadBEShort (short & a_Value);
|
||||
bool ReadBEUInt16 (UInt16 & a_Value);
|
||||
bool ReadBEInt (int & a_Value);
|
||||
bool ReadBEUInt32 (UInt32 & a_Value);
|
||||
bool ReadBEInt64 (Int64 & a_Value);
|
||||
bool ReadBEFloat (float & a_Value);
|
||||
bool ReadBEDouble (double & a_Value);
|
||||
|
|
|
@ -1445,7 +1445,7 @@ void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_
|
|||
|
||||
|
||||
|
||||
void cClientHandle::HandleAnimation(char a_Animation)
|
||||
void cClientHandle::HandleAnimation(int a_Animation)
|
||||
{
|
||||
if (cPluginManager::Get()->CallHookPlayerAnimation(*m_Player, a_Animation))
|
||||
{
|
||||
|
@ -2832,7 +2832,7 @@ void cClientHandle::PacketUnknown(UInt32 a_PacketType)
|
|||
|
||||
|
||||
|
||||
void cClientHandle::PacketError(unsigned char a_PacketType)
|
||||
void cClientHandle::PacketError(UInt32 a_PacketType)
|
||||
{
|
||||
LOGERROR("Protocol error while parsing packet type 0x%02x; disconnecting client \"%s\"", a_PacketType, m_Username.c_str());
|
||||
SendDisconnect("Protocol error");
|
||||
|
|
|
@ -251,10 +251,10 @@ public:
|
|||
// Calls that cProtocol descendants use to report state:
|
||||
void PacketBufferFull(void);
|
||||
void PacketUnknown(UInt32 a_PacketType);
|
||||
void PacketError(unsigned char a_PacketType);
|
||||
void PacketError(UInt32 a_PacketType);
|
||||
|
||||
// Calls that cProtocol descendants use for handling packets:
|
||||
void HandleAnimation(char a_Animation);
|
||||
void HandleAnimation(int a_Animation);
|
||||
|
||||
/** Called when the protocol receives a MC|ItemName plugin message, indicating that the player named
|
||||
an item in the anvil UI. */
|
||||
|
|
|
@ -55,7 +55,7 @@ void cHTTPMessage::AddHeader(const AString & a_Key, const AString & a_Value)
|
|||
}
|
||||
else if (Key == "content-length")
|
||||
{
|
||||
m_ContentLength = atoi(m_Headers[Key].c_str());
|
||||
m_ContentLength = static_cast<size_t>(atol(m_Headers[Key].c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -199,16 +199,16 @@ public:
|
|||
Vector3i m_Pos;
|
||||
BLOCKTYPE m_ReplacedBlock;
|
||||
|
||||
virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
|
||||
virtual bool OnNextBlock(int a_CBBlockX, int a_CBBlockY, int a_CBBlockZ, BLOCKTYPE a_CBBlockType, NIBBLETYPE a_CBBlockMeta, char a_CBEntryFace) override
|
||||
{
|
||||
if (a_BlockType != E_BLOCK_AIR)
|
||||
if (a_CBBlockType != E_BLOCK_AIR)
|
||||
{
|
||||
m_ReplacedBlock = a_BlockType;
|
||||
if (!cFluidSimulator::CanWashAway(a_BlockType) && !IsBlockLiquid(a_BlockType))
|
||||
m_ReplacedBlock = a_CBBlockType;
|
||||
if (!cFluidSimulator::CanWashAway(a_CBBlockType) && !IsBlockLiquid(a_CBBlockType))
|
||||
{
|
||||
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace); // Was an unwashawayable block, can't overwrite it!
|
||||
AddFaceDirection(a_CBBlockX, a_CBBlockY, a_CBBlockZ, (eBlockFace)a_CBEntryFace); // Was an unwashawayable block, can't overwrite it!
|
||||
}
|
||||
m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); // (Block could be washed away, replace it)
|
||||
m_Pos.Set(a_CBBlockX, a_CBBlockY, a_CBBlockZ); // (Block could be washed away, replace it)
|
||||
return true; // Abort tracing
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -34,7 +34,7 @@ void PrintStackTrace(void)
|
|||
// Use the backtrace() function to get and output the stackTrace:
|
||||
// Code adapted from http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
|
||||
void * stackTrace[30];
|
||||
size_t numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace));
|
||||
int numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace));
|
||||
backtrace_symbols_fd(stackTrace, numItems, STDERR_FILENO);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -174,10 +174,10 @@ void cProtocol172::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha
|
|||
|
||||
cPacketizer Pkt(*this, 0x24); // Block Action packet
|
||||
Pkt.WriteInt(a_BlockX);
|
||||
Pkt.WriteShort(a_BlockY);
|
||||
Pkt.WriteShort(static_cast<short>(a_BlockY));
|
||||
Pkt.WriteInt(a_BlockZ);
|
||||
Pkt.WriteByte(a_Byte1);
|
||||
Pkt.WriteByte(a_Byte2);
|
||||
Pkt.WriteByte(static_cast<Byte>(a_Byte1));
|
||||
Pkt.WriteByte(static_cast<Byte>(a_Byte2));
|
||||
Pkt.WriteVarInt(a_BlockType);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ void cProtocol172::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0x25); // Block Break Animation packet
|
||||
Pkt.WriteVarInt(a_EntityID);
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_EntityID));
|
||||
Pkt.WriteInt(a_BlockX);
|
||||
Pkt.WriteInt(a_BlockY);
|
||||
Pkt.WriteInt(a_BlockZ);
|
||||
|
@ -204,10 +204,11 @@ void cProtocol172::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY
|
|||
void cProtocol172::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
ASSERT((a_BlockY >= 0) && (a_BlockY < 256));
|
||||
|
||||
cPacketizer Pkt(*this, 0x23); // Block Change packet
|
||||
Pkt.WriteInt(a_BlockX);
|
||||
Pkt.WriteByte(a_BlockY);
|
||||
Pkt.WriteByte(static_cast<Byte>(a_BlockY));
|
||||
Pkt.WriteInt(a_BlockZ);
|
||||
Pkt.WriteVarInt(a_BlockType);
|
||||
Pkt.WriteByte(a_BlockMeta);
|
||||
|
@ -228,8 +229,8 @@ void cProtocol172::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV
|
|||
Pkt.WriteInt((int)a_Changes.size() * 4);
|
||||
for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr)
|
||||
{
|
||||
unsigned int Coords = itr->m_RelY | (itr->m_RelZ << 8) | (itr->m_RelX << 12);
|
||||
unsigned int Blocks = itr->m_BlockMeta | (itr->m_BlockType << 4);
|
||||
int Coords = itr->m_RelY | (itr->m_RelZ << 8) | (itr->m_RelX << 12);
|
||||
int Blocks = static_cast<int>(itr->m_BlockMeta | (itr->m_BlockType << 4));
|
||||
Pkt.WriteInt((Coords << 16) | Blocks);
|
||||
} // for itr - a_Changes[]
|
||||
}
|
||||
|
@ -352,11 +353,13 @@ void cProtocol172::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ)
|
|||
void cProtocol172::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
ASSERT((a_EffectID >= 0) && (a_EffectID < 256));
|
||||
ASSERT((a_Amplifier >= 0) && (a_Amplifier < 256));
|
||||
|
||||
cPacketizer Pkt(*this, 0x1D); // Entity Effect packet
|
||||
Pkt.WriteInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteByte(a_EffectID);
|
||||
Pkt.WriteByte(a_Amplifier);
|
||||
Pkt.WriteByte(static_cast<Byte>(a_EffectID));
|
||||
Pkt.WriteByte(static_cast<Byte>(a_Amplifier));
|
||||
Pkt.WriteShort(a_Duration);
|
||||
}
|
||||
|
||||
|
@ -438,9 +441,9 @@ void cProtocol172::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char
|
|||
|
||||
cPacketizer Pkt(*this, 0x15); // Entity Relative Move packet
|
||||
Pkt.WriteInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteByte(a_RelX);
|
||||
Pkt.WriteByte(a_RelY);
|
||||
Pkt.WriteByte(a_RelZ);
|
||||
Pkt.WriteChar(a_RelX);
|
||||
Pkt.WriteChar(a_RelY);
|
||||
Pkt.WriteChar(a_RelZ);
|
||||
}
|
||||
|
||||
|
||||
|
@ -453,9 +456,9 @@ void cProtocol172::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX,
|
|||
|
||||
cPacketizer Pkt(*this, 0x17); // Entity Look And Relative Move packet
|
||||
Pkt.WriteInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteByte(a_RelX);
|
||||
Pkt.WriteByte(a_RelY);
|
||||
Pkt.WriteByte(a_RelZ);
|
||||
Pkt.WriteChar(a_RelX);
|
||||
Pkt.WriteChar(a_RelY);
|
||||
Pkt.WriteChar(a_RelZ);
|
||||
Pkt.WriteByteAngle(a_Entity.GetYaw());
|
||||
Pkt.WriteByteAngle(a_Entity.GetPitch());
|
||||
}
|
||||
|
@ -537,9 +540,9 @@ void cProtocol172::SendHealth(void)
|
|||
|
||||
cPacketizer Pkt(*this, 0x06); // Update Health packet
|
||||
cPlayer * Player = m_Client->GetPlayer();
|
||||
Pkt.WriteFloat((float)Player->GetHealth());
|
||||
Pkt.WriteShort(Player->GetFoodLevel());
|
||||
Pkt.WriteFloat((float)Player->GetFoodSaturationLevel());
|
||||
Pkt.WriteFloat(static_cast<float>(Player->GetHealth()));
|
||||
Pkt.WriteShort(static_cast<short>(Player->GetFoodLevel()));
|
||||
Pkt.WriteFloat(static_cast<float>(Player->GetFoodSaturationLevel()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -584,10 +587,10 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
|
|||
cServer * Server = cRoot::Get()->GetServer();
|
||||
cPacketizer Pkt(*this, 0x01); // Join Game packet
|
||||
Pkt.WriteInt(a_Player.GetUniqueID());
|
||||
Pkt.WriteByte((Byte)a_Player.GetEffectiveGameMode() | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4
|
||||
Pkt.WriteChar((char)a_World.GetDimension());
|
||||
Pkt.WriteByte(static_cast<Byte>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4
|
||||
Pkt.WriteChar(static_cast<char>(a_World.GetDimension()));
|
||||
Pkt.WriteByte(2); // TODO: Difficulty (set to Normal)
|
||||
Pkt.WriteByte(std::min(Server->GetMaxPlayers(), 60));
|
||||
Pkt.WriteByte(static_cast<Byte>(std::min(Server->GetMaxPlayers(), 60)));
|
||||
Pkt.WriteString("default"); // Level type - wtf?
|
||||
}
|
||||
m_LastSentDimension = a_World.GetDimension();
|
||||
|
@ -595,9 +598,9 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
|
|||
// Send the spawn position:
|
||||
{
|
||||
cPacketizer Pkt(*this, 0x05); // Spawn Position packet
|
||||
Pkt.WriteInt((int)a_World.GetSpawnX());
|
||||
Pkt.WriteInt((int)a_World.GetSpawnY());
|
||||
Pkt.WriteInt((int)a_World.GetSpawnZ());
|
||||
Pkt.WriteInt(static_cast<int>(a_World.GetSpawnX()));
|
||||
Pkt.WriteInt(static_cast<int>(a_World.GetSpawnY()));
|
||||
Pkt.WriteInt(static_cast<int>(a_World.GetSpawnZ()));
|
||||
}
|
||||
|
||||
// Send player abilities:
|
||||
|
@ -629,11 +632,11 @@ void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting)
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0x10); // Spawn Painting packet
|
||||
Pkt.WriteVarInt(a_Painting.GetUniqueID());
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_Painting.GetUniqueID()));
|
||||
Pkt.WriteString(a_Painting.GetName().c_str());
|
||||
Pkt.WriteInt((int)a_Painting.GetPosX());
|
||||
Pkt.WriteInt((int)a_Painting.GetPosY());
|
||||
Pkt.WriteInt((int)a_Painting.GetPosZ());
|
||||
Pkt.WriteInt(static_cast<int>(a_Painting.GetPosX()));
|
||||
Pkt.WriteInt(static_cast<int>(a_Painting.GetPosY()));
|
||||
Pkt.WriteInt(static_cast<int>(a_Painting.GetPosZ()));
|
||||
Pkt.WriteInt(a_Painting.GetDirection());
|
||||
}
|
||||
|
||||
|
@ -644,19 +647,19 @@ void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting)
|
|||
void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
ASSERT(a_Length + 3 <= USHRT_MAX);
|
||||
ASSERT((a_X >= 0) && (a_X < 256));
|
||||
ASSERT((a_Y >= 0) && (a_Y < 256));
|
||||
|
||||
cPacketizer Pkt(*this, 0x34);
|
||||
Pkt.WriteVarInt(a_ID);
|
||||
Pkt.WriteShort (3 + a_Length);
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_ID));
|
||||
Pkt.WriteShort (static_cast<short>(3 + a_Length));
|
||||
|
||||
Pkt.WriteByte(0);
|
||||
Pkt.WriteByte(a_X);
|
||||
Pkt.WriteByte(a_Y);
|
||||
Pkt.WriteByte(static_cast<Byte>(a_X));
|
||||
Pkt.WriteByte(static_cast<Byte>(a_Y));
|
||||
|
||||
for (unsigned int i = 0; i < a_Length; ++i)
|
||||
{
|
||||
Pkt.WriteByte(a_Colors[i]);
|
||||
}
|
||||
Pkt.WriteBuf(reinterpret_cast<const char *>(a_Colors), a_Length);
|
||||
}
|
||||
|
||||
|
||||
|
@ -666,18 +669,21 @@ void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo
|
|||
void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
ASSERT(1 + 3 * a_Decorators.size() < USHRT_MAX);
|
||||
|
||||
cPacketizer Pkt(*this, 0x34);
|
||||
Pkt.WriteVarInt(a_ID);
|
||||
Pkt.WriteShort ((short)(1 + (3 * a_Decorators.size())));
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_ID));
|
||||
Pkt.WriteShort (static_cast<short>(1 + (3 * a_Decorators.size())));
|
||||
|
||||
Pkt.WriteByte(1);
|
||||
|
||||
for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it)
|
||||
{
|
||||
Pkt.WriteByte((it->GetType() << 4) | (it->GetRot() & 0xf));
|
||||
Pkt.WriteByte(it->GetPixelX());
|
||||
Pkt.WriteByte(it->GetPixelZ());
|
||||
ASSERT((it->GetPixelX() >= 0) && (it->GetPixelX() < 256));
|
||||
ASSERT((it->GetPixelZ() >= 0) && (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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -688,13 +694,14 @@ 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));
|
||||
|
||||
cPacketizer Pkt(*this, 0x34);
|
||||
Pkt.WriteVarInt(a_ID);
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_ID));
|
||||
Pkt.WriteShort (2);
|
||||
|
||||
Pkt.WriteByte(2);
|
||||
Pkt.WriteByte(a_Scale);
|
||||
Pkt.WriteByte(static_cast<Byte>(a_Scale));
|
||||
}
|
||||
|
||||
|
||||
|
@ -707,7 +714,7 @@ void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup)
|
|||
|
||||
{
|
||||
cPacketizer Pkt(*this, 0x0e); // Spawn Object packet
|
||||
Pkt.WriteVarInt(a_Pickup.GetUniqueID());
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_Pickup.GetUniqueID()));
|
||||
Pkt.WriteByte(2); // Type = Pickup
|
||||
Pkt.WriteFPInt(a_Pickup.GetPosX());
|
||||
Pkt.WriteFPInt(a_Pickup.GetPosY());
|
||||
|
@ -763,7 +770,7 @@ void cProtocol172::SendEntityAnimation(const cEntity & a_Entity, char a_Animatio
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0x0b); // Animation packet
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_Entity.GetUniqueID()));
|
||||
Pkt.WriteChar(a_Animation);
|
||||
}
|
||||
|
||||
|
@ -865,7 +872,7 @@ void cProtocol172::SendPlayerMaxSpeed(void)
|
|||
{
|
||||
Pkt.WriteShort(1); // Modifier count
|
||||
Pkt.WriteInt64(0x662a6b8dda3e4c1c);
|
||||
Pkt.WriteInt64(0x881396ea6097278d); // UUID of the modifier
|
||||
Pkt.WriteInt64(static_cast<Int64>(0x881396ea6097278d)); // UUID of the modifier
|
||||
Pkt.WriteDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed());
|
||||
Pkt.WriteByte(2);
|
||||
}
|
||||
|
@ -960,10 +967,11 @@ void cProtocol172::SendPluginMessage(const AString & a_Channel, const AString &
|
|||
void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
ASSERT((a_EffectID >= 0) && (a_EffectID < 256));
|
||||
|
||||
cPacketizer Pkt(*this, 0x1e);
|
||||
Pkt.WriteInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteByte(a_EffectID);
|
||||
Pkt.WriteByte(static_cast<Byte>(a_EffectID));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1009,13 +1017,14 @@ void cProtocol172::SendExperience (void)
|
|||
void cProtocol172::SendExperienceOrb(const cExpOrb & a_ExpOrb)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
ASSERT((a_ExpOrb.GetReward() >= 0) && (a_ExpOrb.GetReward() < SHRT_MAX));
|
||||
|
||||
cPacketizer Pkt(*this, 0x11);
|
||||
Pkt.WriteVarInt(a_ExpOrb.GetUniqueID());
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_ExpOrb.GetUniqueID()));
|
||||
Pkt.WriteFPInt(a_ExpOrb.GetPosX());
|
||||
Pkt.WriteFPInt(a_ExpOrb.GetPosY());
|
||||
Pkt.WriteFPInt(a_ExpOrb.GetPosZ());
|
||||
Pkt.WriteShort(a_ExpOrb.GetReward());
|
||||
Pkt.WriteShort(static_cast<short>(a_ExpOrb.GetReward()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1060,7 +1069,7 @@ void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0x3d);
|
||||
Pkt.WriteByte((int) a_Display);
|
||||
Pkt.WriteByte(static_cast<Byte>(a_Display));
|
||||
Pkt.WriteString(a_Objective);
|
||||
}
|
||||
|
||||
|
@ -1074,11 +1083,11 @@ void cProtocol172::SendSoundEffect(const AString & a_SoundName, double a_X, doub
|
|||
|
||||
cPacketizer Pkt(*this, 0x29); // Sound Effect packet
|
||||
Pkt.WriteString(a_SoundName);
|
||||
Pkt.WriteInt((int)(a_X * 8.0));
|
||||
Pkt.WriteInt((int)(a_Y * 8.0));
|
||||
Pkt.WriteInt((int)(a_Z * 8.0));
|
||||
Pkt.WriteInt(static_cast<int>(a_X * 8.0));
|
||||
Pkt.WriteInt(static_cast<int>(a_Y * 8.0));
|
||||
Pkt.WriteInt(static_cast<int>(a_Z * 8.0));
|
||||
Pkt.WriteFloat(a_Volume);
|
||||
Pkt.WriteByte((Byte)(a_Pitch * 63));
|
||||
Pkt.WriteByte(static_cast<Byte>(a_Pitch * 63));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1088,11 +1097,12 @@ void cProtocol172::SendSoundEffect(const AString & a_SoundName, double a_X, doub
|
|||
void cProtocol172::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data)
|
||||
{
|
||||
ASSERT(m_State == 3); // In game mode?
|
||||
ASSERT((a_SrcY >= 0) && (a_SrcY < 256));
|
||||
|
||||
cPacketizer Pkt(*this, 0x28); // Effect packet
|
||||
Pkt.WriteInt(a_EffectID);
|
||||
Pkt.WriteInt(a_SrcX);
|
||||
Pkt.WriteByte(a_SrcY);
|
||||
Pkt.WriteByte(static_cast<Byte>(a_SrcY));
|
||||
Pkt.WriteInt(a_SrcZ);
|
||||
Pkt.WriteInt(a_Data);
|
||||
Pkt.WriteBool(false);
|
||||
|
@ -1107,17 +1117,17 @@ void cProtocol172::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock)
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0x0e); // Spawn Object packet
|
||||
Pkt.WriteVarInt(a_FallingBlock.GetUniqueID());
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_FallingBlock.GetUniqueID()));
|
||||
Pkt.WriteByte(70); // Falling block
|
||||
Pkt.WriteFPInt(a_FallingBlock.GetPosX());
|
||||
Pkt.WriteFPInt(a_FallingBlock.GetPosY());
|
||||
Pkt.WriteFPInt(a_FallingBlock.GetPosZ());
|
||||
Pkt.WriteByteAngle(a_FallingBlock.GetYaw());
|
||||
Pkt.WriteByteAngle(a_FallingBlock.GetPitch());
|
||||
Pkt.WriteInt(((int)a_FallingBlock.GetBlockType()) | (((int)a_FallingBlock.GetBlockMeta()) << 16)); // Or 0x10
|
||||
Pkt.WriteShort((short)(a_FallingBlock.GetSpeedX() * 400));
|
||||
Pkt.WriteShort((short)(a_FallingBlock.GetSpeedY() * 400));
|
||||
Pkt.WriteShort((short)(a_FallingBlock.GetSpeedZ() * 400));
|
||||
Pkt.WriteInt((static_cast<int>(a_FallingBlock.GetBlockType()) | ((static_cast<int>(a_FallingBlock.GetBlockMeta()) << 16))));
|
||||
Pkt.WriteShort(static_cast<short>(a_FallingBlock.GetSpeedX() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_FallingBlock.GetSpeedY() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_FallingBlock.GetSpeedZ() * 400));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1129,7 +1139,7 @@ void cProtocol172::SendSpawnMob(const cMonster & a_Mob)
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0x0f); // Spawn Mob packet
|
||||
Pkt.WriteVarInt(a_Mob.GetUniqueID());
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_Mob.GetUniqueID()));
|
||||
Pkt.WriteByte((Byte)a_Mob.GetMobType());
|
||||
Pkt.WriteFPInt(a_Mob.GetPosX());
|
||||
Pkt.WriteFPInt(a_Mob.GetPosY());
|
||||
|
@ -1137,9 +1147,9 @@ void cProtocol172::SendSpawnMob(const cMonster & a_Mob)
|
|||
Pkt.WriteByteAngle(a_Mob.GetPitch());
|
||||
Pkt.WriteByteAngle(a_Mob.GetHeadYaw());
|
||||
Pkt.WriteByteAngle(a_Mob.GetYaw());
|
||||
Pkt.WriteShort((short)(a_Mob.GetSpeedX() * 400));
|
||||
Pkt.WriteShort((short)(a_Mob.GetSpeedY() * 400));
|
||||
Pkt.WriteShort((short)(a_Mob.GetSpeedZ() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Mob.GetSpeedX() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Mob.GetSpeedY() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Mob.GetSpeedZ() * 400));
|
||||
Pkt.WriteEntityMetadata(a_Mob);
|
||||
Pkt.WriteByte(0x7f); // Metadata terminator
|
||||
}
|
||||
|
@ -1153,8 +1163,8 @@ void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0xe); // Spawn Object packet
|
||||
Pkt.WriteVarInt(a_Entity.GetUniqueID());
|
||||
Pkt.WriteByte(a_ObjectType);
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_Entity.GetUniqueID()));
|
||||
Pkt.WriteChar(a_ObjectType);
|
||||
Pkt.WriteFPInt(a_Entity.GetPosX());
|
||||
Pkt.WriteFPInt(a_Entity.GetPosY());
|
||||
Pkt.WriteFPInt(a_Entity.GetPosZ());
|
||||
|
@ -1163,9 +1173,9 @@ void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
|
|||
Pkt.WriteInt(a_ObjectData);
|
||||
if (a_ObjectData != 0)
|
||||
{
|
||||
Pkt.WriteShort((short)(a_Entity.GetSpeedX() * 400));
|
||||
Pkt.WriteShort((short)(a_Entity.GetSpeedY() * 400));
|
||||
Pkt.WriteShort((short)(a_Entity.GetSpeedZ() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Entity.GetSpeedX() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Entity.GetSpeedY() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Entity.GetSpeedZ() * 400));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1178,8 +1188,8 @@ void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0xe); // Spawn Object packet
|
||||
Pkt.WriteVarInt(a_Vehicle.GetUniqueID());
|
||||
Pkt.WriteByte(a_VehicleType);
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_Vehicle.GetUniqueID()));
|
||||
Pkt.WriteChar(a_VehicleType);
|
||||
Pkt.WriteFPInt(a_Vehicle.GetPosX());
|
||||
Pkt.WriteFPInt(a_Vehicle.GetPosY());
|
||||
Pkt.WriteFPInt(a_Vehicle.GetPosZ());
|
||||
|
@ -1188,9 +1198,9 @@ void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp
|
|||
Pkt.WriteInt(a_VehicleSubType);
|
||||
if (a_VehicleSubType != 0)
|
||||
{
|
||||
Pkt.WriteShort((short)(a_Vehicle.GetSpeedX() * 400));
|
||||
Pkt.WriteShort((short)(a_Vehicle.GetSpeedY() * 400));
|
||||
Pkt.WriteShort((short)(a_Vehicle.GetSpeedZ() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedX() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedY() * 400));
|
||||
Pkt.WriteShort(static_cast<short>(a_Vehicle.GetSpeedZ() * 400));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1211,7 +1221,7 @@ void cProtocol172::SendStatistics(const cStatManager & a_Manager)
|
|||
const AString & StatName = cStatInfo::GetName((eStatistic) i);
|
||||
|
||||
Pkt.WriteString(StatName);
|
||||
Pkt.WriteVarInt(Value);
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1224,7 +1234,7 @@ void cProtocol172::SendTabCompletionResults(const AStringVector & a_Results)
|
|||
ASSERT(m_State == 3); // In game mode?
|
||||
|
||||
cPacketizer Pkt(*this, 0x3a); // Tab-Complete packet
|
||||
Pkt.WriteVarInt((int)a_Results.size());
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_Results.size()));
|
||||
|
||||
for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr)
|
||||
{
|
||||
|
@ -1309,7 +1319,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
|
|||
|
||||
cPacketizer Pkt(*this, 0x35); // Update tile entity packet
|
||||
Pkt.WriteInt(a_BlockEntity.GetPosX());
|
||||
Pkt.WriteShort(a_BlockEntity.GetPosY());
|
||||
Pkt.WriteShort(static_cast<short>(a_BlockEntity.GetPosY()));
|
||||
Pkt.WriteInt(a_BlockEntity.GetPosZ());
|
||||
|
||||
Byte Action = 0;
|
||||
|
@ -1389,7 +1399,7 @@ void cProtocol172::SendWholeInventory(const cWindow & a_Window)
|
|||
|
||||
cPacketizer Pkt(*this, 0x30); // Window Items packet
|
||||
Pkt.WriteChar(a_Window.GetWindowID());
|
||||
Pkt.WriteShort(a_Window.GetNumSlots());
|
||||
Pkt.WriteShort(static_cast<short>(a_Window.GetNumSlots()));
|
||||
cItems Slots;
|
||||
a_Window.GetSlots(*(m_Client->GetPlayer()), Slots);
|
||||
for (cItems::const_iterator itr = Slots.begin(), end = Slots.end(); itr != end; ++itr)
|
||||
|
@ -1426,9 +1436,9 @@ void cProtocol172::SendWindowOpen(const cWindow & a_Window)
|
|||
|
||||
cPacketizer Pkt(*this, 0x2d);
|
||||
Pkt.WriteChar(a_Window.GetWindowID());
|
||||
Pkt.WriteChar(a_Window.GetWindowType());
|
||||
Pkt.WriteChar(static_cast<char>(a_Window.GetWindowType()));
|
||||
Pkt.WriteString(a_Window.GetWindowTitle());
|
||||
Pkt.WriteChar(a_Window.GetNumNonInventorySlots());
|
||||
Pkt.WriteChar(static_cast<char>(a_Window.GetNumNonInventorySlots()));
|
||||
Pkt.WriteBool(true);
|
||||
if (a_Window.GetWindowType() == cWindow::wtAnimalChest)
|
||||
{
|
||||
|
@ -1505,7 +1515,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
|
|||
break;
|
||||
}
|
||||
cByteBuffer bb(PacketLen + 1);
|
||||
VERIFY(m_ReceivedData.ReadToByteBuffer(bb, (int)PacketLen));
|
||||
VERIFY(m_ReceivedData.ReadToByteBuffer(bb, static_cast<size_t>(PacketLen)));
|
||||
m_ReceivedData.CommitRead();
|
||||
|
||||
UInt32 PacketType;
|
||||
|
@ -1748,8 +1758,14 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe
|
|||
{
|
||||
short EncKeyLength, EncNonceLength;
|
||||
a_ByteBuffer.ReadBEShort(EncKeyLength);
|
||||
if ((EncKeyLength < 0) || (EncKeyLength > MAX_ENC_LEN))
|
||||
{
|
||||
LOGD("Invalid Encryption Key length: %d. Kicking client.", EncKeyLength);
|
||||
m_Client->Kick("Invalid EncKeyLength");
|
||||
return;
|
||||
}
|
||||
AString EncKey;
|
||||
if (!a_ByteBuffer.ReadString(EncKey, EncKeyLength))
|
||||
if (!a_ByteBuffer.ReadString(EncKey, static_cast<size_t>(EncKeyLength)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1757,15 +1773,15 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe
|
|||
{
|
||||
return;
|
||||
}
|
||||
AString EncNonce;
|
||||
if (!a_ByteBuffer.ReadString(EncNonce, EncNonceLength))
|
||||
if ((EncNonceLength < 0) || (EncNonceLength > MAX_ENC_LEN))
|
||||
{
|
||||
LOGD("Invalid Encryption Nonce length: %d. Kicking client.", EncNonceLength);
|
||||
m_Client->Kick("Invalid EncNonceLength");
|
||||
return;
|
||||
}
|
||||
if ((EncKeyLength > MAX_ENC_LEN) || (EncNonceLength > MAX_ENC_LEN))
|
||||
AString EncNonce;
|
||||
if (!a_ByteBuffer.ReadString(EncNonce, static_cast<size_t>(EncNonceLength)))
|
||||
{
|
||||
LOGD("Too long encryption");
|
||||
m_Client->Kick("Hacked client");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1854,7 +1870,7 @@ void cProtocol172::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
|
|||
|
||||
void cProtocol172::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
|
||||
{
|
||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Status);
|
||||
HANDLE_READ(a_ByteBuffer, ReadChar, char, Status);
|
||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
|
||||
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, BlockY);
|
||||
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
|
||||
|
@ -2072,7 +2088,7 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
|
|||
if (Length + 1 != (int)a_ByteBuffer.GetReadableSpace())
|
||||
{
|
||||
LOGD("Invalid plugin message packet, payload length doesn't match packet length (exp %d, got %d)",
|
||||
(int)a_ByteBuffer.GetReadableSpace() - 1, Length
|
||||
static_cast<int>(a_ByteBuffer.GetReadableSpace()) - 1, Length
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -2086,7 +2102,7 @@ void cProtocol172::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
|
|||
|
||||
// Read the plugin message and relay to clienthandle:
|
||||
AString Data;
|
||||
if (!a_ByteBuffer.ReadString(Data, Length))
|
||||
if (!a_ByteBuffer.ReadString(Data, static_cast<size_t>(Length)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -2274,7 +2290,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||
LOGD("Protocol 1.7: Skipping garbage data at the end of a vanilla MC|AdvCdm packet, %u bytes",
|
||||
static_cast<unsigned>(a_PayloadLength - BytesRead)
|
||||
);
|
||||
a_ByteBuffer.SkipRead(a_PayloadLength - BytesRead);
|
||||
a_ByteBuffer.SkipRead(static_cast<size_t>(a_PayloadLength) - BytesRead);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -2282,7 +2298,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||
{
|
||||
// Read the client's brand:
|
||||
AString Brand;
|
||||
if (a_ByteBuffer.ReadString(Brand, a_PayloadLength))
|
||||
if (a_ByteBuffer.ReadString(Brand, static_cast<size_t>(a_PayloadLength)))
|
||||
{
|
||||
m_Client->SetClientBrand(Brand);
|
||||
}
|
||||
|
@ -2301,7 +2317,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||
else if (a_Channel == "MC|ItemName")
|
||||
{
|
||||
AString ItemName;
|
||||
if (a_ByteBuffer.ReadString(ItemName, a_PayloadLength))
|
||||
if (a_ByteBuffer.ReadString(ItemName, static_cast<size_t>(a_PayloadLength)))
|
||||
{
|
||||
m_Client->HandleAnvilItemName(ItemName);
|
||||
}
|
||||
|
@ -2317,7 +2333,7 @@ void cProtocol172::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const
|
|||
|
||||
// Read the payload and send it through to the clienthandle:
|
||||
AString Message;
|
||||
VERIFY(a_ByteBuffer.ReadString(Message, a_PayloadLength));
|
||||
VERIFY(a_ByteBuffer.ReadString(Message, static_cast<size_t>(a_PayloadLength)));
|
||||
m_Client->HandlePluginMessage(a_Channel, Message);
|
||||
}
|
||||
|
||||
|
@ -2377,7 +2393,7 @@ bool cProtocol172::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item)
|
|||
|
||||
// Read the metadata
|
||||
AString Metadata;
|
||||
if (!a_ByteBuffer.ReadString(Metadata, MetadataLength))
|
||||
if (!a_ByteBuffer.ReadString(Metadata, static_cast<size_t>(MetadataLength)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -2546,7 +2562,7 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item)
|
|||
}
|
||||
|
||||
WriteShort(ItemType);
|
||||
WriteByte (a_Item.m_ItemCount);
|
||||
WriteChar (a_Item.m_ItemCount);
|
||||
WriteShort(a_Item.m_ItemDamage);
|
||||
|
||||
if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty() && (a_Item.m_ItemType != E_ITEM_FIREWORK_ROCKET) && (a_Item.m_ItemType != E_ITEM_FIREWORK_STAR))
|
||||
|
@ -2706,7 +2722,7 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
|
|||
|
||||
void cProtocol172::cPacketizer::WriteByteAngle(double a_Angle)
|
||||
{
|
||||
WriteByte((char)(255 * a_Angle / 360));
|
||||
WriteChar(static_cast<char>(255 * a_Angle / 360));
|
||||
}
|
||||
|
||||
|
||||
|
@ -2849,7 +2865,7 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
|
|||
case mtCreeper:
|
||||
{
|
||||
WriteByte(0x10);
|
||||
WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1);
|
||||
WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : 0);
|
||||
WriteByte(0x11);
|
||||
WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0);
|
||||
break;
|
||||
|
@ -2918,15 +2934,14 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
|
|||
WriteByte(0x13);
|
||||
WriteByte(Wolf.IsBegging() ? 1 : 0);
|
||||
WriteByte(0x14);
|
||||
WriteByte(Wolf.GetCollarColor());
|
||||
WriteByte(static_cast<Byte>(Wolf.GetCollarColor()));
|
||||
break;
|
||||
}
|
||||
|
||||
case mtSheep:
|
||||
{
|
||||
WriteByte(0x10);
|
||||
Byte SheepMetadata = 0;
|
||||
SheepMetadata = ((const cSheep &)a_Mob).GetFurColor();
|
||||
Byte SheepMetadata = static_cast<Byte>(((const cSheep &)a_Mob).GetFurColor() & 0x0f);
|
||||
if (((const cSheep &)a_Mob).IsSheared())
|
||||
{
|
||||
SheepMetadata |= 0x10;
|
||||
|
@ -2963,7 +2978,7 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
|
|||
case mtWither:
|
||||
{
|
||||
WriteByte(0x54); // Int at index 20
|
||||
WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks());
|
||||
WriteInt(static_cast<int>(((const cWither &)a_Mob).GetWitherInvulnerableTicks()));
|
||||
WriteByte(0x66); // Float at index 6
|
||||
WriteFloat((float)(a_Mob.GetHealth()));
|
||||
break;
|
||||
|
@ -2972,14 +2987,14 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
|
|||
case mtSlime:
|
||||
{
|
||||
WriteByte(0x10);
|
||||
WriteByte(((const cSlime &)a_Mob).GetSize());
|
||||
WriteByte(static_cast<Byte>(((const cSlime &)a_Mob).GetSize()));
|
||||
break;
|
||||
}
|
||||
|
||||
case mtMagmaCube:
|
||||
{
|
||||
WriteByte(0x10);
|
||||
WriteByte(((const cMagmaCube &)a_Mob).GetSize());
|
||||
WriteByte(static_cast<Byte>(((const cMagmaCube &)a_Mob).GetSize()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3018,7 +3033,7 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
|
|||
WriteByte(0x50); // Int at index 16
|
||||
WriteInt(Flags);
|
||||
WriteByte(0x13); // Byte at index 19
|
||||
WriteByte(Horse.GetHorseType());
|
||||
WriteByte(static_cast<Byte>(Horse.GetHorseType()));
|
||||
WriteByte(0x54); // Int at index 20
|
||||
int Appearance = 0;
|
||||
Appearance = Horse.GetHorseColor();
|
||||
|
@ -3028,6 +3043,12 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
|
|||
WriteInt(Horse.GetHorseArmour());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
// No data to send for this mob
|
||||
break;
|
||||
}
|
||||
} // switch (a_Mob.GetType())
|
||||
|
||||
// Custom name:
|
||||
|
@ -3080,7 +3101,7 @@ void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player)
|
|||
{
|
||||
// Called to spawn another player for the client
|
||||
cPacketizer Pkt(*this, 0x0c); // Spawn Player packet
|
||||
Pkt.WriteVarInt(a_Player.GetUniqueID());
|
||||
Pkt.WriteVarInt(static_cast<UInt32>(a_Player.GetUniqueID()));
|
||||
Pkt.WriteString(cMojangAPI::MakeUUIDDashed(a_Player.GetClientHandle()->GetUUID()));
|
||||
if (a_Player.HasCustomName())
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ AString & AppendVPrintf(AString & str, const char * format, va_list args)
|
|||
ASSERT(format != nullptr);
|
||||
|
||||
char buffer[2048];
|
||||
size_t len;
|
||||
int len;
|
||||
#ifdef va_copy
|
||||
va_list argsCopy;
|
||||
va_copy(argsCopy, args);
|
||||
|
@ -34,14 +34,14 @@ AString & AppendVPrintf(AString & str, const char * format, va_list args)
|
|||
// MS CRT provides secure printf that doesn't behave like in the C99 standard
|
||||
if ((len = _vsnprintf_s(buffer, ARRAYCOUNT(buffer), _TRUNCATE, format, argsCopy)) != -1)
|
||||
#else // _MSC_VER
|
||||
if ((len = vsnprintf(buffer, ARRAYCOUNT(buffer), format, argsCopy)) < ARRAYCOUNT(buffer))
|
||||
if ((len = vsnprintf(buffer, ARRAYCOUNT(buffer), format, argsCopy)) < static_cast<int>(ARRAYCOUNT(buffer)))
|
||||
#endif // else _MSC_VER
|
||||
{
|
||||
// The result did fit into the static buffer
|
||||
#ifdef va_copy
|
||||
va_end(argsCopy);
|
||||
#endif
|
||||
str.append(buffer, len);
|
||||
str.append(buffer, static_cast<size_t>(len));
|
||||
return str;
|
||||
}
|
||||
#ifdef va_copy
|
||||
|
@ -51,7 +51,6 @@ AString & AppendVPrintf(AString & str, const char * format, va_list args)
|
|||
// The result did not fit into the static buffer, use a dynamic buffer:
|
||||
#ifdef _MSC_VER
|
||||
// for MS CRT, we need to calculate the result length
|
||||
// MS doesn't have va_copy() and does nod need it at all
|
||||
len = _vscprintf(format, args);
|
||||
if (len == -1)
|
||||
{
|
||||
|
@ -63,11 +62,11 @@ AString & AppendVPrintf(AString & str, const char * format, va_list args)
|
|||
#ifdef va_copy
|
||||
va_copy(argsCopy, args);
|
||||
#endif
|
||||
std::vector<char> Buffer(len + 1);
|
||||
std::vector<char> Buffer(static_cast<size_t>(len) + 1);
|
||||
#ifdef _MSC_VER
|
||||
vsprintf_s((char *)&(Buffer.front()), Buffer.size(), format, argsCopy);
|
||||
vsprintf_s(&(Buffer.front()), Buffer.size(), format, argsCopy);
|
||||
#else // _MSC_VER
|
||||
vsnprintf((char *)&(Buffer.front()), Buffer.size(), format, argsCopy);
|
||||
vsnprintf(&(Buffer.front()), Buffer.size(), format, argsCopy);
|
||||
#endif // else _MSC_VER
|
||||
str.append(&(Buffer.front()), Buffer.size() - 1);
|
||||
#ifdef va_copy
|
||||
|
@ -85,7 +84,7 @@ AString & Printf(AString & str, const char * format, ...)
|
|||
str.clear();
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
std::string &retval = AppendVPrintf(str, format, args);
|
||||
std::string & retval = AppendVPrintf(str, format, args);
|
||||
va_end(args);
|
||||
return retval;
|
||||
}
|
||||
|
@ -108,11 +107,11 @@ AString Printf(const char * format, ...)
|
|||
|
||||
|
||||
|
||||
AString & AppendPrintf(AString &str, const char * format, ...)
|
||||
AString & AppendPrintf(AString & dst, const char * format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
std::string &retval = AppendVPrintf(str, format, args);
|
||||
std::string & retval = AppendVPrintf(dst, format, args);
|
||||
va_end(args);
|
||||
return retval;
|
||||
}
|
||||
|
@ -297,7 +296,6 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString &
|
|||
|
||||
|
||||
|
||||
// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
|
||||
AString & RawBEToUTF8(const char * a_RawData, size_t a_NumShorts, AString & a_UTF8)
|
||||
{
|
||||
a_UTF8.clear();
|
||||
|
@ -314,22 +312,22 @@ AString & RawBEToUTF8(const char * a_RawData, size_t a_NumShorts, AString & a_UT
|
|||
a_UTF8.push_back((char)(192 + c / 64));
|
||||
a_UTF8.push_back((char)(128 + c % 64));
|
||||
}
|
||||
else if (c - 0xd800u < 0x800)
|
||||
else if (c - 0xd800 < 0x800)
|
||||
{
|
||||
// Error, silently drop
|
||||
}
|
||||
else if (c < 0x10000)
|
||||
{
|
||||
a_UTF8.push_back((char)(224 + c / 4096));
|
||||
a_UTF8.push_back((char)(128 + c / 64 % 64));
|
||||
a_UTF8.push_back((char)(128 + c % 64));
|
||||
a_UTF8.push_back(static_cast<char>(224 + c / 4096));
|
||||
a_UTF8.push_back(static_cast<char>(128 + (c / 64) % 64));
|
||||
a_UTF8.push_back(static_cast<char>(128 + c % 64));
|
||||
}
|
||||
else if (c < 0x110000)
|
||||
{
|
||||
a_UTF8.push_back((char)(240 + c / 262144));
|
||||
a_UTF8.push_back((char)(128 + c / 4096 % 64));
|
||||
a_UTF8.push_back((char)(128 + c / 64 % 64));
|
||||
a_UTF8.push_back((char)(128 + c % 64));
|
||||
a_UTF8.push_back(static_cast<char>(240 + c / 262144));
|
||||
a_UTF8.push_back(static_cast<char>(128 + (c / 4096) % 64));
|
||||
a_UTF8.push_back(static_cast<char>(128 + (c / 64) % 64));
|
||||
a_UTF8.push_back(static_cast<char>(128 + c % 64));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -382,7 +380,7 @@ Notice from the original file:
|
|||
|
||||
|
||||
|
||||
static const char trailingBytesForUTF8[256] =
|
||||
static const Byte trailingBytesForUTF8[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -572,18 +570,18 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, siz
|
|||
int Count = sprintf(line, "%08x:", (unsigned)i);
|
||||
#endif
|
||||
// Remove the terminating nullptr / leftover garbage in line, after the sprintf-ed value
|
||||
memset(line + Count, 32, sizeof(line) - Count);
|
||||
memset(line + Count, 32, sizeof(line) - static_cast<size_t>(Count));
|
||||
p = line + 10;
|
||||
q = p + 2 + a_BytesPerLine * 3 + 1;
|
||||
for (size_t j = 0; j < k; j++)
|
||||
{
|
||||
unsigned char c = ((unsigned char *)a_Data)[i + j];
|
||||
Byte c = (reinterpret_cast<const Byte *>(a_Data))[i + j];
|
||||
p[0] = HEX(c >> 4);
|
||||
p[1] = HEX(c & 0xf);
|
||||
p[2] = ' ';
|
||||
if (c >= ' ')
|
||||
{
|
||||
q[0] = (char)c;
|
||||
q[0] = static_cast<char>(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -708,7 +706,7 @@ AString URLDecode(const AString & a_String)
|
|||
res.push_back(ch);
|
||||
continue;
|
||||
}
|
||||
res.push_back((hi << 4) | lo);
|
||||
res.push_back(static_cast<char>((hi << 4) | lo));
|
||||
i += 2;
|
||||
} // for i - a_String[]
|
||||
return res;
|
||||
|
@ -767,7 +765,8 @@ AString Base64Decode(const AString & a_Base64String)
|
|||
{
|
||||
AString res;
|
||||
size_t i, len = a_Base64String.size();
|
||||
int o, c;
|
||||
size_t o;
|
||||
int c;
|
||||
res.resize((len * 4) / 3 + 5, 0); // Approximate the upper bound on the result length
|
||||
for (o = 0, i = 0; i < len; i++)
|
||||
{
|
||||
|
@ -850,7 +849,7 @@ AString Base64Encode(const AString & a_Input)
|
|||
short GetBEShort(const char * a_Mem)
|
||||
{
|
||||
const Byte * Bytes = (const Byte *)a_Mem;
|
||||
return (Bytes[0] << 8) | Bytes[1];
|
||||
return static_cast<short>((Bytes[0] << 8) | Bytes[1]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -870,9 +869,9 @@ int GetBEInt(const char * a_Mem)
|
|||
void SetBEInt(char * a_Mem, Int32 a_Value)
|
||||
{
|
||||
a_Mem[0] = a_Value >> 24;
|
||||
a_Mem[1] = (a_Value >> 16) & 0xff;
|
||||
a_Mem[2] = (a_Value >> 8) & 0xff;
|
||||
a_Mem[3] = a_Value & 0xff;
|
||||
a_Mem[1] = static_cast<char>((a_Value >> 16) & 0xff);
|
||||
a_Mem[2] = static_cast<char>((a_Value >> 8) & 0xff);
|
||||
a_Mem[3] = static_cast<char>(a_Value & 0xff);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,31 +21,40 @@ typedef std::list<AString> AStringList;
|
|||
|
||||
|
||||
|
||||
/** Add the formated string to the existing data in the string */
|
||||
extern AString & AppendVPrintf(AString & str, const char * format, va_list args) FORMATSTRING(2, 0);
|
||||
/** Add the formated string to the existing data in the string.
|
||||
Returns a_Dst. */
|
||||
extern AString & AppendVPrintf(AString & a_Dst, const char * format, va_list args) FORMATSTRING(2, 0);
|
||||
|
||||
/// Output the formatted text into the string
|
||||
extern AString & Printf (AString & str, const char * format, ...) FORMATSTRING(2, 3);
|
||||
/** Output the formatted text into the string.
|
||||
Returns a_Dst. */
|
||||
extern AString & Printf (AString & a_Dst, const char * format, ...) FORMATSTRING(2, 3);
|
||||
|
||||
/// Output the formatted text into string, return string by value
|
||||
/** Output the formatted text into string
|
||||
Returns the formatted string by value. */
|
||||
extern AString Printf(const char * format, ...) FORMATSTRING(1, 2);
|
||||
|
||||
/// Add the formatted string to the existing data in the string
|
||||
extern AString & AppendPrintf (AString & str, const char * format, ...) FORMATSTRING(2, 3);
|
||||
/** Add the formatted string to the existing data in the string.
|
||||
Returns a_Dst */
|
||||
extern AString & AppendPrintf (AString & a_Dst, const char * format, ...) FORMATSTRING(2, 3);
|
||||
|
||||
/// Split the string at any of the listed delimiters, return as a stringvector
|
||||
/** Split the string at any of the listed delimiters.
|
||||
Return the splitted strings as a stringvector. */
|
||||
extern AStringVector StringSplit(const AString & str, const AString & delim);
|
||||
|
||||
/// Split the string at any of the listed delimiters and trim each value, return as a stringvector
|
||||
/** Split the string at any of the listed delimiters and trim each value.
|
||||
Returns the splitted strings as a stringvector. */
|
||||
extern AStringVector StringSplitAndTrim(const AString & str, const AString & delim);
|
||||
|
||||
/// Trime whitespace at both ends of the string
|
||||
/** Trims whitespace at both ends of the string.
|
||||
Returns a trimmed copy of the original string. */
|
||||
extern AString TrimString(const AString & str); // tolua_export
|
||||
|
||||
/// In-place string conversion to uppercase; returns the same string
|
||||
/** In-place string conversion to uppercase.
|
||||
Returns the same string object. */
|
||||
extern AString & InPlaceUppercase(AString & s);
|
||||
|
||||
/// In-place string conversion to lowercase; returns the same string
|
||||
/** In-place string conversion to lowercase.
|
||||
Returns the same string object. */
|
||||
extern AString & InPlaceLowercase(AString & s);
|
||||
|
||||
/** Returns an upper-cased copy of the string */
|
||||
|
@ -54,28 +63,30 @@ extern AString StrToUpper(const AString & s);
|
|||
/** Returns a lower-cased copy of the string */
|
||||
extern AString StrToLower(const AString & s);
|
||||
|
||||
/// Case-insensitive string comparison; returns 0 if the strings are the same
|
||||
/** Case-insensitive string comparison.
|
||||
Returns 0 if the strings are the same, <0 if s1 < s2 and >0 if s1 > s2. */
|
||||
extern int NoCaseCompare(const AString & s1, const AString & s2); // tolua_export
|
||||
|
||||
/// Case-insensitive string comparison that returns a rating of equal-ness between [0 - s1.length()]
|
||||
/** Case-insensitive string comparison that returns a rating of equal-ness between [0 - s1.length()]. */
|
||||
extern size_t RateCompareString(const AString & s1, const AString & s2);
|
||||
|
||||
/// Replaces *each* occurence of iNeedle in iHayStack with iReplaceWith
|
||||
/** Replaces *each* occurence of iNeedle in iHayStack with iReplaceWith */
|
||||
extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export
|
||||
|
||||
/// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
|
||||
/** Converts a stream of BE shorts into UTF-8 string; returns a_UTF8. */
|
||||
extern AString & RawBEToUTF8(const char * a_RawData, size_t a_NumShorts, AString & a_UTF8);
|
||||
|
||||
/// Converts a UTF-8 string into a UTF-16 BE string; returns a ref to a_UTF16
|
||||
/** Converts a UTF-8 string into a UTF-16 BE string. */
|
||||
extern AString UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length);
|
||||
|
||||
/// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120
|
||||
/** Creates a nicely formatted HEX dump of the given memory block.
|
||||
Max a_BytesPerLine is 120. */
|
||||
extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine);
|
||||
|
||||
/// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash
|
||||
/** Returns a copy of a_Message with all quotes and backslashes escaped by a backslash. */
|
||||
extern AString EscapeString(const AString & a_Message); // tolua_export
|
||||
|
||||
/// Removes all control codes used by MC for colors and styles
|
||||
/** Removes all control codes used by MC for colors and styles. */
|
||||
extern AString StripColorCodes(const AString & a_Message); // tolua_export
|
||||
|
||||
/// URL-Decodes the given string, replacing all "%HH" into the correct characters. Invalid % sequences are left intact
|
||||
|
|
|
@ -803,7 +803,7 @@ public:
|
|||
int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed = nullptr); // tolua_export
|
||||
|
||||
/** Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! */
|
||||
int GetTickRandomNumber(unsigned a_Range) { return (int)(m_TickRand.randInt(a_Range)); }
|
||||
int GetTickRandomNumber(int a_Range) { return (int)(m_TickRand.randInt(a_Range)); }
|
||||
|
||||
/** Appends all usernames starting with a_Text (case-insensitive) into Results */
|
||||
void TabCompleteUserName(const AString & a_Text, AStringVector & a_Results);
|
||||
|
|
|
@ -109,7 +109,7 @@ bool cParsedNBT::ReadCompound(void)
|
|||
ASSERT(m_Tags.size() > 0);
|
||||
|
||||
// Reads the latest tag as a compound
|
||||
int ParentIdx = (int)m_Tags.size() - 1;
|
||||
size_t ParentIdx = m_Tags.size() - 1;
|
||||
int PrevSibling = -1;
|
||||
for (;;)
|
||||
{
|
||||
|
@ -120,10 +120,10 @@ bool cParsedNBT::ReadCompound(void)
|
|||
{
|
||||
break;
|
||||
}
|
||||
m_Tags.push_back(cFastNBTTag(TagType, ParentIdx, PrevSibling));
|
||||
m_Tags.push_back(cFastNBTTag(TagType, static_cast<int>(ParentIdx), PrevSibling));
|
||||
if (PrevSibling >= 0)
|
||||
{
|
||||
m_Tags[PrevSibling].m_NextSibling = (int)m_Tags.size() - 1;
|
||||
m_Tags[static_cast<size_t>(PrevSibling)].m_NextSibling = (int)m_Tags.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -155,20 +155,21 @@ bool cParsedNBT::ReadList(eTagType a_ChildrenType)
|
|||
}
|
||||
|
||||
// Read items:
|
||||
int ParentIdx = (int)m_Tags.size() - 1;
|
||||
ASSERT(m_Tags.size() > 0);
|
||||
size_t ParentIdx = m_Tags.size() - 1;
|
||||
int PrevSibling = -1;
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
m_Tags.push_back(cFastNBTTag(a_ChildrenType, ParentIdx, PrevSibling));
|
||||
m_Tags.push_back(cFastNBTTag(a_ChildrenType, static_cast<int>(ParentIdx), PrevSibling));
|
||||
if (PrevSibling >= 0)
|
||||
{
|
||||
m_Tags[PrevSibling].m_NextSibling = (int)m_Tags.size() - 1;
|
||||
m_Tags[static_cast<size_t>(PrevSibling)].m_NextSibling = static_cast<int>(m_Tags.size()) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Tags[ParentIdx].m_FirstChild = (int)m_Tags.size() - 1;
|
||||
m_Tags[ParentIdx].m_FirstChild = static_cast<int>(m_Tags.size()) - 1;
|
||||
}
|
||||
PrevSibling = (int)m_Tags.size() - 1;
|
||||
PrevSibling = static_cast<int>(m_Tags.size()) - 1;
|
||||
RETURN_FALSE_IF_FALSE(ReadTag());
|
||||
} // for (i)
|
||||
m_Tags[ParentIdx].m_LastChild = PrevSibling;
|
||||
|
@ -217,16 +218,16 @@ bool cParsedNBT::ReadTag(void)
|
|||
return false;
|
||||
}
|
||||
NEEDBYTES(len);
|
||||
Tag.m_DataLength = len;
|
||||
Tag.m_DataLength = static_cast<size_t>(len);
|
||||
Tag.m_DataStart = m_Pos;
|
||||
m_Pos += len;
|
||||
m_Pos += static_cast<size_t>(len);
|
||||
return true;
|
||||
}
|
||||
|
||||
case TAG_List:
|
||||
{
|
||||
NEEDBYTES(1);
|
||||
eTagType ItemType = (eTagType)m_Data[m_Pos];
|
||||
eTagType ItemType = static_cast<eTagType>(m_Data[m_Pos]);
|
||||
m_Pos++;
|
||||
RETURN_FALSE_IF_FALSE(ReadList(ItemType));
|
||||
return true;
|
||||
|
@ -250,9 +251,9 @@ bool cParsedNBT::ReadTag(void)
|
|||
}
|
||||
len *= 4;
|
||||
NEEDBYTES(len);
|
||||
Tag.m_DataLength = len;
|
||||
Tag.m_DataLength = static_cast<size_t>(len);
|
||||
Tag.m_DataStart = m_Pos;
|
||||
m_Pos += len;
|
||||
m_Pos += static_cast<size_t>(len);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -276,7 +277,7 @@ int cParsedNBT::FindChildByName(int a_Tag, const char * a_Name, size_t a_NameLen
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
if (m_Tags[a_Tag].m_Type != TAG_Compound)
|
||||
if (m_Tags[static_cast<size_t>(a_Tag)].m_Type != TAG_Compound)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -285,11 +286,11 @@ int cParsedNBT::FindChildByName(int a_Tag, const char * a_Name, size_t a_NameLen
|
|||
{
|
||||
a_NameLength = strlen(a_Name);
|
||||
}
|
||||
for (int Child = m_Tags[a_Tag].m_FirstChild; Child != -1; Child = m_Tags[Child].m_NextSibling)
|
||||
for (int Child = m_Tags[static_cast<size_t>(a_Tag)].m_FirstChild; Child != -1; Child = m_Tags[static_cast<size_t>(Child)].m_NextSibling)
|
||||
{
|
||||
if (
|
||||
(m_Tags[Child].m_NameLength == a_NameLength) &&
|
||||
(memcmp(m_Data + m_Tags[Child].m_NameStart, a_Name, a_NameLength) == 0)
|
||||
(m_Tags[static_cast<size_t>(Child)].m_NameLength == a_NameLength) &&
|
||||
(memcmp(m_Data + m_Tags[static_cast<size_t>(Child)].m_NameStart, a_Name, a_NameLength) == 0)
|
||||
)
|
||||
{
|
||||
return Child;
|
||||
|
@ -413,7 +414,7 @@ void cFastNBTWriter::EndList(void)
|
|||
ASSERT(m_Stack[m_CurrentStack].m_Type == TAG_List);
|
||||
|
||||
// Update the list count:
|
||||
SetBEInt((char *)(m_Result.c_str() + m_Stack[m_CurrentStack].m_Pos), m_Stack[m_CurrentStack].m_Count);
|
||||
SetBEInt(const_cast<char *>(m_Result.c_str() + m_Stack[m_CurrentStack].m_Pos), m_Stack[m_CurrentStack].m_Count);
|
||||
|
||||
--m_CurrentStack;
|
||||
}
|
||||
|
@ -425,7 +426,7 @@ void cFastNBTWriter::EndList(void)
|
|||
void cFastNBTWriter::AddByte(const AString & a_Name, unsigned char a_Value)
|
||||
{
|
||||
TagCommon(a_Name, TAG_Byte);
|
||||
m_Result.push_back(a_Value);
|
||||
m_Result.push_back(static_cast<char>(a_Value));
|
||||
}
|
||||
|
||||
|
||||
|
@ -435,8 +436,8 @@ void cFastNBTWriter::AddByte(const AString & a_Name, unsigned char a_Value)
|
|||
void cFastNBTWriter::AddShort(const AString & a_Name, Int16 a_Value)
|
||||
{
|
||||
TagCommon(a_Name, TAG_Short);
|
||||
Int16 Value = htons(a_Value);
|
||||
m_Result.append((const char *)&Value, 2);
|
||||
UInt16 Value = htons(a_Value);
|
||||
m_Result.append(reinterpret_cast<const char *>(&Value), 2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -446,8 +447,8 @@ void cFastNBTWriter::AddShort(const AString & a_Name, Int16 a_Value)
|
|||
void cFastNBTWriter::AddInt(const AString & a_Name, Int32 a_Value)
|
||||
{
|
||||
TagCommon(a_Name, TAG_Int);
|
||||
Int32 Value = htonl(a_Value);
|
||||
m_Result.append((const char *)&Value, 4);
|
||||
UInt32 Value = htonl(a_Value);
|
||||
m_Result.append(reinterpret_cast<const char *>(&Value), 4);
|
||||
}
|
||||
|
||||
|
||||
|
@ -457,8 +458,8 @@ void cFastNBTWriter::AddInt(const AString & a_Name, Int32 a_Value)
|
|||
void cFastNBTWriter::AddLong(const AString & a_Name, Int64 a_Value)
|
||||
{
|
||||
TagCommon(a_Name, TAG_Long);
|
||||
Int64 Value = HostToNetwork8(&a_Value);
|
||||
m_Result.append((const char *)&Value, 8);
|
||||
UInt64 Value = HostToNetwork8(&a_Value);
|
||||
m_Result.append(reinterpret_cast<const char *>(&Value), 8);
|
||||
}
|
||||
|
||||
|
||||
|
@ -468,8 +469,8 @@ void cFastNBTWriter::AddLong(const AString & a_Name, Int64 a_Value)
|
|||
void cFastNBTWriter::AddFloat(const AString & a_Name, float a_Value)
|
||||
{
|
||||
TagCommon(a_Name, TAG_Float);
|
||||
Int32 Value = HostToNetwork4(&a_Value);
|
||||
m_Result.append((const char *)&Value, 4);
|
||||
UInt32 Value = HostToNetwork4(&a_Value);
|
||||
m_Result.append(reinterpret_cast<const char *>(&Value), 4);
|
||||
}
|
||||
|
||||
|
||||
|
@ -479,8 +480,8 @@ void cFastNBTWriter::AddFloat(const AString & a_Name, float a_Value)
|
|||
void cFastNBTWriter::AddDouble(const AString & a_Name, double a_Value)
|
||||
{
|
||||
TagCommon(a_Name, TAG_Double);
|
||||
Int64 Value = HostToNetwork8(&a_Value);
|
||||
m_Result.append((const char *)&Value, 8);
|
||||
UInt64 Value = HostToNetwork8(&a_Value);
|
||||
m_Result.append(reinterpret_cast<const char *>(&Value), 8);
|
||||
}
|
||||
|
||||
|
||||
|
@ -490,8 +491,8 @@ void cFastNBTWriter::AddDouble(const AString & a_Name, double a_Value)
|
|||
void cFastNBTWriter::AddString(const AString & a_Name, const AString & a_Value)
|
||||
{
|
||||
TagCommon(a_Name, TAG_String);
|
||||
Int16 len = htons((short)(a_Value.size()));
|
||||
m_Result.append((const char *)&len, 2);
|
||||
UInt16 len = htons(static_cast<short>(a_Value.size()));
|
||||
m_Result.append(reinterpret_cast<const char *>(&len), 2);
|
||||
m_Result.append(a_Value.c_str(), a_Value.size());
|
||||
}
|
||||
|
||||
|
@ -502,8 +503,8 @@ void cFastNBTWriter::AddString(const AString & a_Name, const AString & a_Value)
|
|||
void cFastNBTWriter::AddByteArray(const AString & a_Name, const char * a_Value, size_t a_NumElements)
|
||||
{
|
||||
TagCommon(a_Name, TAG_ByteArray);
|
||||
u_long len = htonl((u_long)a_NumElements);
|
||||
m_Result.append((const char *)&len, 4);
|
||||
u_long len = htonl(static_cast<u_long>(a_NumElements));
|
||||
m_Result.append(reinterpret_cast<const char *>(&len), 4);
|
||||
m_Result.append(a_Value, a_NumElements);
|
||||
}
|
||||
|
||||
|
@ -514,18 +515,18 @@ void cFastNBTWriter::AddByteArray(const AString & a_Name, const char * a_Value,
|
|||
void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, size_t a_NumElements)
|
||||
{
|
||||
TagCommon(a_Name, TAG_IntArray);
|
||||
u_long len = htonl((u_long)a_NumElements);
|
||||
u_long len = htonl(static_cast<u_long>(a_NumElements));
|
||||
size_t cap = m_Result.capacity();
|
||||
size_t size = m_Result.length();
|
||||
if ((cap - size) < (4 + a_NumElements * 4))
|
||||
{
|
||||
m_Result.reserve(size + 4 + (a_NumElements * 4));
|
||||
}
|
||||
m_Result.append((const char *)&len, 4);
|
||||
m_Result.append(reinterpret_cast<const char *>(&len), 4);
|
||||
for (size_t i = 0; i < a_NumElements; i++)
|
||||
{
|
||||
int Element = htonl(a_Value[i]);
|
||||
m_Result.append((const char *)&Element, 4);
|
||||
UInt32 Element = htonl(a_Value[i]);
|
||||
m_Result.append(reinterpret_cast<const char *>(&Element), 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -545,8 +546,8 @@ void cFastNBTWriter::Finish(void)
|
|||
|
||||
void cFastNBTWriter::WriteString(const char * a_Data, UInt16 a_Length)
|
||||
{
|
||||
Int16 Len = htons(a_Length);
|
||||
m_Result.append((const char *)&Len, 2);
|
||||
UInt16 Len = htons(a_Length);
|
||||
m_Result.append(reinterpret_cast<const char *>(&Len), 2);
|
||||
m_Result.append(a_Data, a_Length);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue