summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-06-20 16:25:21 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-06-20 16:25:21 +0200
commitba2e09672bf88ed1016fc82bd88ac87df0a5b3a1 (patch)
tree3d3308541e5350d4639e217cb519fe55a34f6c45 /src/network
parent2017-06-17 (diff)
downloadAltCraft-ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1.tar
AltCraft-ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1.tar.gz
AltCraft-ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1.tar.bz2
AltCraft-ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1.tar.lz
AltCraft-ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1.tar.xz
AltCraft-ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1.tar.zst
AltCraft-ba2e09672bf88ed1016fc82bd88ac87df0a5b3a1.zip
Diffstat (limited to '')
-rw-r--r--src/network/Network.cpp6
-rw-r--r--src/network/Packet.hpp54
-rw-r--r--src/network/Stream.cpp41
3 files changed, 75 insertions, 26 deletions
diff --git a/src/network/Network.cpp b/src/network/Network.cpp
index 59c4e00..68df158 100644
--- a/src/network/Network.cpp
+++ b/src/network/Network.cpp
@@ -210,6 +210,12 @@ std::shared_ptr<Packet> Network::ParsePacketPlay(PacketNamePlayCB id) {
break;
case EntityEffect:
break;
+ case UnlockRecipes:
+ break;
+ case SelectAdvancementTab:
+ break;
+ case Advancements:
+ break;
}
return nullptr;
}
diff --git a/src/network/Packet.hpp b/src/network/Packet.hpp
index 9249a34..3cf4d26 100644
--- a/src/network/Packet.hpp
+++ b/src/network/Packet.hpp
@@ -237,7 +237,7 @@ struct PacketJoinGame : Packet {
struct PacketDisconnectPlay : Packet {
void ToStream(StreamOutput *stream) override {
-
+ stream->WriteString(Reason); //TODO: Implement chat-wrapper
}
void FromStream(StreamInput *stream) override {
@@ -253,7 +253,7 @@ struct PacketDisconnectPlay : Packet {
struct PacketSpawnPosition : Packet {
void ToStream(StreamOutput *stream) override {
-
+ stream->WritePosition(Location);
}
void FromStream(StreamInput *stream) override {
@@ -303,7 +303,13 @@ struct PacketKeepAliveSB : Packet {
struct PacketPlayerPositionAndLookCB : Packet {
void ToStream(StreamOutput *stream) override {
-
+ stream->WriteDouble(X);
+ stream->WriteDouble(Y);
+ stream->WriteDouble(Z);
+ stream->WriteFloat(Yaw);
+ stream->WriteFloat(Pitch);
+ stream->WriteUByte(Flags);
+ stream->WriteVarInt(TeleportId);
}
void FromStream(StreamInput *stream) override {
@@ -376,7 +382,12 @@ struct PacketPlayerPositionAndLookSB : Packet {
}
void FromStream(StreamInput *stream) override {
-
+ X = stream->ReadDouble();
+ FeetY = stream->ReadDouble();
+ Z = stream->ReadDouble();
+ Yaw = stream->ReadFloat();
+ Pitch = stream->ReadFloat();
+ OnGround = stream->ReadBool();
}
int GetPacketId() override {
@@ -398,7 +409,14 @@ struct PacketPlayerPositionAndLookSB : Packet {
struct PacketChunkData : Packet {
void ToStream(StreamOutput *stream) override {
-
+ stream->WriteInt(ChunkX);
+ stream->WriteInt(ChunkZ);
+ stream->WriteBool(GroundUpContinuous);
+ stream->WriteInt(PrimaryBitMask);
+ stream->WriteVarInt(Data.size());
+ stream->WriteByteArray(Data);
+ stream->WriteVarInt(BlockEntities.size());
+ LOG(FATAL) << "Serializing unimplemented packet";
}
void FromStream(StreamInput *stream) override {
@@ -406,9 +424,12 @@ struct PacketChunkData : Packet {
ChunkZ = stream->ReadInt();
GroundUpContinuous = stream->ReadBool();
PrimaryBitMask = stream->ReadVarInt();
- Size = stream->ReadVarInt();
+ int Size = stream->ReadVarInt();
Data = stream->ReadByteArray(Size);
- NumberOfBlockEntities = stream->ReadVarInt();
+ int NumberOfBlockEntities = stream->ReadVarInt(); //TODO: Need NBT
+ for (int i = 0; i < NumberOfBlockEntities; i++) {
+ //BlockEntities[i] = stream->ReadNbt();
+ }
}
int GetPacketId() override {
@@ -419,10 +440,10 @@ struct PacketChunkData : Packet {
int ChunkZ;
bool GroundUpContinuous;
int PrimaryBitMask;
- int Size;
+ //int Size;
std::vector<unsigned char> Data;
- int NumberOfBlockEntities;
- //std::vector<NbtTag> BlockEntities;
+ //int NumberOfBlockEntities;
+ std::vector<int> BlockEntities; //TODO: Replace int with NbtTag and implement NbtTree
};
struct PacketPlayerPosition : Packet {
@@ -434,7 +455,10 @@ struct PacketPlayerPosition : Packet {
}
void FromStream(StreamInput *stream) override {
-
+ X = stream->ReadDouble();
+ FeetY = stream->ReadDouble();
+ Z = stream->ReadDouble();
+ OnGround = stream->ReadBool();
}
int GetPacketId() override {
@@ -457,7 +481,9 @@ struct PacketPlayerLook : Packet {
}
void FromStream(StreamInput *stream) override {
-
+ Yaw = stream->ReadFloat();
+ Pitch = stream->ReadFloat();
+ OnGround = stream->ReadBool();
}
int GetPacketId() override {
@@ -473,7 +499,9 @@ struct PacketPlayerLook : Packet {
struct PacketUpdateHealth : Packet {
void ToStream(StreamOutput *stream) override {
-
+ stream->WriteFloat(Health);
+ stream->WriteVarInt(Food);
+ stream->WriteFloat(FoodSaturation);
}
void FromStream(StreamInput *stream) override {
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<unsigned char> value) {
-
+ LOG(FATAL) << "Used unimplemented WriteEntityMetadata: " << value.size();
}
void StreamOutput::WriteSlot(std::vector<unsigned char> value) {
-
+ LOG(FATAL) << "Used unimplemented WriteSlot " << value.size();
}
void StreamOutput::WriteNbtTag(std::vector<unsigned char> 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<unsigned char> value) {
-
+ WriteByteArray(value);
}
void StreamOutput::WriteByteArray(std::vector<unsigned char> value) {
-
+ WriteData(value.data(), value.size());
}
void StreamBuffer::ReadData(unsigned char *buffPtr, size_t buffLen) {
@@ -306,6 +320,7 @@ std::vector<unsigned char> StreamBuffer::GetBuffer() {
}
void StreamCounter::WriteData(unsigned char *buffPtr, size_t buffLen) {
+ buffPtr++;
size += buffLen;
}