From 4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Thu, 18 May 2017 19:03:05 +0500 Subject: 2017-05-18 --- src/packet/PacketBuilder.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/packet/PacketBuilder.cpp (limited to 'src/packet/PacketBuilder.cpp') diff --git a/src/packet/PacketBuilder.cpp b/src/packet/PacketBuilder.cpp new file mode 100644 index 0000000..4083ea3 --- /dev/null +++ b/src/packet/PacketBuilder.cpp @@ -0,0 +1,65 @@ +#include "PacketBuilder.hpp" + +Packet PacketBuilder::CHandshaking0x00(int protocolVerison, std::string address, unsigned short port, int nextState) { + Packet handshakePacket(0); + Field fProtocol; + fProtocol.SetVarInt(protocolVerison); + Field fAddress; + fAddress.SetString(address); + Field fPort; + fPort.SetUShort(port); + Field fNextState; + fNextState.SetVarInt(nextState); + handshakePacket.AddField(fProtocol); + handshakePacket.AddField(fAddress); + handshakePacket.AddField(fPort); + handshakePacket.AddField(fNextState); + return handshakePacket; +} + +Packet PacketBuilder::CPlay0x0B(int keepAliveId) { + Packet keepAlivePacket(0x0B); + Field fKeepAlive; + fKeepAlive.SetVarInt(keepAliveId); + keepAlivePacket.AddField(fKeepAlive); + return keepAlivePacket; +} + +Packet PacketBuilder::CPlay0x03(int actionId) { + Packet clientStatusPacket(0x03); + Field fActionId; + fActionId.SetVarInt(actionId); + clientStatusPacket.AddField(fActionId); + return clientStatusPacket; +} + +Packet PacketBuilder::CPlay0x00(int teleportId) { + Packet teleportConfirmPacket(0x00); + Field fTeleportId; + fTeleportId.SetVarInt(teleportId); + teleportConfirmPacket.AddField(fTeleportId); + return teleportConfirmPacket; +} + +Packet PacketBuilder::CPlay0x0D(double x, double y, double z, float yaw, float pitch, bool onGround) { + Packet playerPositionAndLookPacket(0x0D); + Field fX; + Field fY; + Field fZ; + Field fYaw; + Field fPitch; + Field fOnGround; + fX.SetDouble(x); + fY.SetDouble(y); + fZ.SetDouble(z); + fYaw.SetFloat(yaw); + fPitch.SetFloat(pitch); + fOnGround.SetBool(onGround); + playerPositionAndLookPacket.AddField(fX); + playerPositionAndLookPacket.AddField(fY); + playerPositionAndLookPacket.AddField(fZ); + playerPositionAndLookPacket.AddField(fYaw); + playerPositionAndLookPacket.AddField(fPitch); + playerPositionAndLookPacket.AddField(fOnGround); + return playerPositionAndLookPacket; +} -- cgit v1.2.3