summaryrefslogtreecommitdiffstats
path: root/src/packet/Packet.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-06-17 16:23:53 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-06-17 16:23:53 +0200
commit789f70b6f1a9067843dfc1ff73d86b645efe1da9 (patch)
treef3db085f2ac1ec5fd6ad0869a63e77a7f0fb1a17 /src/packet/Packet.cpp
parent2017-06-14 (diff)
downloadAltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar
AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.gz
AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.bz2
AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.lz
AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.xz
AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.zst
AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.zip
Diffstat (limited to '')
-rw-r--r--src/packet/Packet.cpp101
1 files changed, 0 insertions, 101 deletions
diff --git a/src/packet/Packet.cpp b/src/packet/Packet.cpp
deleted file mode 100644
index 68cc3c3..0000000
--- a/src/packet/Packet.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-#include "Packet.hpp"
-
-Packet::Packet(int id) {
- Field fLen;
- fLen.SetVarInt(0);
- m_fields.push_back(fLen);
- Field fId;
- fId.SetVarInt(id);
- m_fields.push_back(fId);
-}
-
-Packet Packet::operator=(Packet other) {
- other.swap(*this);
- return *this;
-}
-
-void Packet::swap(Packet &other) {
- std::swap(m_fields, other.m_fields);
- std::swap(m_data, other.m_data);
- std::swap(m_parsePtr, other.m_parsePtr);
- std::swap(m_dataLength, other.m_dataLength);
-}
-
-void Packet::CopyToBuff(byte *ptr) {
- m_fields[0].SetVarInt(GetLength() - m_fields[0].GetLength());
- for (auto &it:m_fields) {
- it.CopyToBuff(ptr);
- ptr += it.GetLength();
- }
-}
-
-void Packet::ParseField(FieldType type, size_t len) {
- if (type == ByteArray && len == 0)
- throw 118;
- Field f = FieldParser::Parse(type, m_parsePtr, len);
- m_fields.push_back(f);
- m_parsePtr += f.GetLength();
- if (m_parsePtr == m_data + m_dataLength) {
- delete[] m_data;
- m_data = nullptr;
- m_dataLength = 0;
- m_parsePtr = nullptr;
- }
-}
-
-Packet::Packet(byte *data) {
- Field fLen = FieldParser::Parse(VarIntType, data);
- data += fLen.GetLength();
- Field fId = FieldParser::Parse(VarIntType, data);
- data += fId.GetLength();
- m_dataLength = fLen.GetVarInt() - fId.GetLength();
- m_data = new byte[m_dataLength];
- std::copy(data, data + m_dataLength, m_data);
- m_parsePtr = m_data;
- m_fields.push_back(fLen);
- m_fields.push_back(fId);
-}
-
-Field &Packet::GetField(int id) {
- if (id < -2 || id >= (int) m_fields.size() - 2)
- throw 111;
- return m_fields[id + 2];
-}
-
-size_t Packet::GetLength() {
- size_t len = 0;
- for (auto &it:m_fields) {
- len += it.GetLength();
- }
- return len + m_dataLength;
-}
-
-void Packet::AddField(Field field) {
- m_fields.push_back(field);
-}
-
-int Packet::GetId() {
- return m_fields[1].GetVarInt();
-}
-
-Packet::Packet(const Packet &other) {
- if (other.m_dataLength > 0) {
- m_dataLength = other.m_dataLength;
- m_data = new byte[m_dataLength];
- m_parsePtr = m_data + (other.m_data - other.m_parsePtr);
- std::copy(other.m_data, other.m_data + m_dataLength, m_data);
- }
- m_fields = other.m_fields;
-}
-
-void Packet::ParseFieldArray(Field &field, FieldType type, size_t len) {
- Field f = FieldParser::Parse(type, m_parsePtr, len);
- field.Attach(f);
- m_parsePtr += f.GetLength();
- if (m_parsePtr == m_data + m_dataLength) {
- delete[] m_data;
- m_data = nullptr;
- m_dataLength = 0;
- m_parsePtr = nullptr;
- }
-}