From 4c6de9b99184ff96757ff87294513952b6fb1527 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Sun, 8 Jul 2018 23:03:53 -0400 Subject: [PATCH] Steal buffer from SerializeBuffer now --- common/base_packet.cpp | 12 ++++++++++++ common/base_packet.h | 2 ++ common/eq_packet.h | 4 +++- common/serialize_buffer.h | 2 ++ zone/tasks.cpp | 8 ++++---- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/common/base_packet.cpp b/common/base_packet.cpp index ce6afe978..50f9b84f9 100644 --- a/common/base_packet.cpp +++ b/common/base_packet.cpp @@ -39,6 +39,18 @@ BasePacket::BasePacket(const unsigned char *buf, uint32 len) } } +BasePacket::BasePacket(SerializeBuffer &buf) +{ + pBuffer = buf.m_buffer; + buf.m_buffer = nullptr; + size = buf.m_pos; + buf.m_pos = 0; + buf.m_capacity = 0; + _wpos = 0; + _rpos = 0; + timestamp.tv_sec = 0; +} + BasePacket::~BasePacket() { if (pBuffer) diff --git a/common/base_packet.h b/common/base_packet.h index 8d64e6d62..4f47c919a 100644 --- a/common/base_packet.h +++ b/common/base_packet.h @@ -19,6 +19,7 @@ #define BASEPACKET_H_ #include "types.h" +#include "serialize_buffer.h" #include #include @@ -85,6 +86,7 @@ protected: virtual ~BasePacket(); BasePacket() { pBuffer=nullptr; size=0; _wpos = 0; _rpos = 0; } BasePacket(const unsigned char *buf, const uint32 len); + BasePacket(SerializeBuffer &buf); }; extern void DumpPacketHex(const BasePacket* app); diff --git a/common/eq_packet.h b/common/eq_packet.h index 29588cbc1..77b76b450 100644 --- a/common/eq_packet.h +++ b/common/eq_packet.h @@ -20,7 +20,6 @@ #include "base_packet.h" #include "platform.h" -#include "serialize_buffer.h" #include #ifdef STATIC_OPCODE @@ -52,6 +51,7 @@ protected: EmuOpcode emu_opcode; EQPacket(EmuOpcode opcode, const unsigned char *buf, const uint32 len); + EQPacket(EmuOpcode opcode, SerializeBuffer &buf) : BasePacket(buf), emu_opcode(opcode) { }; // EQPacket(const EQPacket &p) { } EQPacket() { emu_opcode=OP_Unknown; pBuffer=nullptr; size=0; } @@ -105,6 +105,8 @@ public: { app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; } EQApplicationPacket(const EmuOpcode op, const unsigned char *buf, const uint32 len) : EQPacket(op, buf, len), opcode_bypass(0) { app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; } + EQApplicationPacket(const EmuOpcode op, SerializeBuffer &buf) : EQPacket(op, buf), opcode_bypass(0) + { app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; } bool combine(const EQApplicationPacket *rhs); uint32 serialize (uint16 opcode, unsigned char *dest) const; uint32 Size() const { return size+app_opcode_size; } diff --git a/common/serialize_buffer.h b/common/serialize_buffer.h index ef6b92593..9b350b4fa 100644 --- a/common/serialize_buffer.h +++ b/common/serialize_buffer.h @@ -186,6 +186,8 @@ public: size_t capacity() const { return m_capacity; } const unsigned char *buffer() const { return m_buffer; } + friend class BasePacket; + private: void Grow(size_t new_size); void Reset(); diff --git a/zone/tasks.cpp b/zone/tasks.cpp index f31beb472..419bbd751 100644 --- a/zone/tasks.cpp +++ b/zone/tasks.cpp @@ -1146,7 +1146,7 @@ void TaskManager::SendTaskSelector(Client *c, Mob *mob, int TaskCount, int *Task } } - auto outapp = new EQApplicationPacket(OP_OpenNewTasksWindow, buf.buffer(), buf.length()); + auto outapp = new EQApplicationPacket(OP_OpenNewTasksWindow, buf); c->QueuePacket(outapp); safe_delete(outapp); @@ -1233,7 +1233,7 @@ void TaskManager::SendTaskSelectorNew(Client *c, Mob *mob, int TaskCount, int *T } } - auto outapp = new EQApplicationPacket(OP_OpenNewTasksWindow, buf.buffer(), buf.length()); + auto outapp = new EQApplicationPacket(OP_OpenNewTasksWindow, buf); c->QueuePacket(outapp); safe_delete(outapp); @@ -2770,7 +2770,7 @@ void TaskManager::SendTaskActivityLong(Client *c, int TaskID, int ActivityID, in buf.WriteUInt32(1); // unknown - auto outapp = new EQApplicationPacket(OP_TaskActivity, buf.buffer(), buf.length()); + auto outapp = new EQApplicationPacket(OP_TaskActivity, buf); c->QueuePacket(outapp); safe_delete(outapp); @@ -2830,7 +2830,7 @@ void TaskManager::SendTaskActivityNew(Client *c, int TaskID, int ActivityID, int buf.WriteString(Tasks[TaskID]->Activity[ActivityID].zones); - auto outapp = new EQApplicationPacket(OP_TaskActivity, buf.buffer(), buf.length()); + auto outapp = new EQApplicationPacket(OP_TaskActivity, buf); c->QueuePacket(outapp); safe_delete(outapp);