From ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Tue, 20 Jun 2017 19:25:21 +0500 Subject: 2017-06-20 --- src/network/Stream.cpp | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'src/network/Stream.cpp') diff --git a/src/network/Stream.cpp b/src/network/Stream.cpp index a0c6cb0..d492428 100644 --- a/src/network/Stream.cpp +++ b/src/network/Stream.cpp @@ -174,16 +174,18 @@ void StreamOutput::WriteBool(bool value) { } void StreamOutput::WriteByte(signed char value) { - + endswap(value); + WriteData((unsigned char *) &value, 1); } void StreamOutput::WriteUByte(unsigned char value) { endswap(value); - WriteData(&value,1); + WriteData(&value, 1); } void StreamOutput::WriteShort(short value) { - + endswap(value); + WriteData((unsigned char *) &value, 2); } void StreamOutput::WriteUShort(unsigned short value) { @@ -197,7 +199,8 @@ void StreamOutput::WriteInt(int value) { } void StreamOutput::WriteLong(long long value) { - + endswap(value); + WriteData((unsigned char *) &value, 8); } void StreamOutput::WriteFloat(float value) { @@ -216,7 +219,7 @@ void StreamOutput::WriteString(std::string value) { } void StreamOutput::WriteChat(std::string value) { - + WriteString(value); } void StreamOutput::WriteVarInt(int value) { @@ -235,35 +238,46 @@ void StreamOutput::WriteVarInt(int value) { } void StreamOutput::WriteVarLong(long long value) { - + unsigned char buff[10]; + size_t len = 0; + do { + unsigned char temp = (unsigned char) (value & 0b01111111); + value >>= 7; + if (value != 0) { + temp |= 0b10000000; + } + buff[len] = temp; + len++; + } while (value != 0); + WriteData(buff, len); } void StreamOutput::WriteEntityMetadata(std::vector value) { - + LOG(FATAL) << "Used unimplemented WriteEntityMetadata: " << value.size(); } void StreamOutput::WriteSlot(std::vector value) { - + LOG(FATAL) << "Used unimplemented WriteSlot " << value.size(); } void StreamOutput::WriteNbtTag(std::vector value) { - + LOG(FATAL) << "Used unimplemented WriteNbtTag " << value.size(); } void StreamOutput::WritePosition(Vector value) { - + LOG(FATAL) << "Used unimplemented Position: " << value.GetX() << ", " << value.GetY() << " " << value.GetZ(); } void StreamOutput::WriteAngle(unsigned char value) { - + WriteUByte(value); } void StreamOutput::WriteUuid(std::vector value) { - + WriteByteArray(value); } void StreamOutput::WriteByteArray(std::vector value) { - + WriteData(value.data(), value.size()); } void StreamBuffer::ReadData(unsigned char *buffPtr, size_t buffLen) { @@ -306,6 +320,7 @@ std::vector StreamBuffer::GetBuffer() { } void StreamCounter::WriteData(unsigned char *buffPtr, size_t buffLen) { + buffPtr++; size += buffLen; } -- cgit v1.2.3