mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-19 21:02:41 +00:00
Packets take SerializeBuffer via move
The existing implemented behavior is that of a transfer of ownership, however it does it without move semantics. This doesn't change the behavior but makes it explicitly clear that there is a transfer of ownership via enforced move semantics. Also includes some cleanup in the packet classes, including converting the size parameter to size_t. While no packet will ever be large enough to require 64-bits of size, many places that are initializing packets are doing so with a size_t parameter, so this will address those warnings here.
This commit is contained in:
parent
48d18aa62a
commit
8bbfca961c
@ -19,44 +19,34 @@
|
|||||||
#include "common/misc.h"
|
#include "common/misc.h"
|
||||||
#include "common/packet_dump.h"
|
#include "common/packet_dump.h"
|
||||||
|
|
||||||
BasePacket::BasePacket(const unsigned char *buf, uint32 len)
|
BasePacket::BasePacket(const unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
pBuffer=nullptr;
|
if (len > 0) {
|
||||||
size=0;
|
size = static_cast<uint32>(len);
|
||||||
_wpos = 0;
|
pBuffer = new unsigned char[len];
|
||||||
_rpos = 0;
|
|
||||||
timestamp.tv_sec = 0;
|
|
||||||
if (len>0) {
|
|
||||||
size=len;
|
|
||||||
pBuffer= new unsigned char[len];
|
|
||||||
if (buf) {
|
if (buf) {
|
||||||
memcpy(pBuffer,buf,len);
|
memcpy(pBuffer, buf, len);
|
||||||
} else {
|
}
|
||||||
memset(pBuffer,0,len);
|
else {
|
||||||
|
memset(pBuffer, 0, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BasePacket::BasePacket(SerializeBuffer &buf)
|
BasePacket::BasePacket(SerializeBuffer&& buf)
|
||||||
|
: pBuffer(std::exchange(buf.m_buffer, nullptr))
|
||||||
{
|
{
|
||||||
pBuffer = buf.m_buffer;
|
// We are essentially taking ownership of this serialize buffer.
|
||||||
buf.m_buffer = nullptr;
|
size = static_cast<uint32>(std::exchange(buf.m_pos, 0));
|
||||||
size = buf.m_pos;
|
|
||||||
buf.m_pos = 0;
|
|
||||||
buf.m_capacity = 0;
|
buf.m_capacity = 0;
|
||||||
_wpos = 0;
|
|
||||||
_rpos = 0;
|
|
||||||
timestamp.tv_sec = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BasePacket::~BasePacket()
|
BasePacket::~BasePacket()
|
||||||
{
|
{
|
||||||
if (pBuffer)
|
|
||||||
delete[] pBuffer;
|
delete[] pBuffer;
|
||||||
pBuffer=nullptr;
|
pBuffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BasePacket::build_raw_header_dump(char *buffer, uint16 seq) const
|
void BasePacket::build_raw_header_dump(char *buffer, uint16 seq) const
|
||||||
{
|
{
|
||||||
if (timestamp.tv_sec) {
|
if (timestamp.tv_sec) {
|
||||||
|
|||||||
@ -23,14 +23,26 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
class BasePacket {
|
class BasePacket
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
BasePacket() = default;
|
||||||
|
BasePacket(const unsigned char* buf, size_t len);
|
||||||
|
BasePacket(SerializeBuffer&& buf);
|
||||||
|
|
||||||
|
virtual ~BasePacket();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
unsigned char *pBuffer;
|
unsigned char* pBuffer = nullptr;
|
||||||
uint32 size, _wpos, _rpos;
|
uint32 size = 0;
|
||||||
uint32 src_ip,dst_ip;
|
uint32 _wpos = 0;
|
||||||
uint16 src_port,dst_port;
|
uint32 _rpos = 0;
|
||||||
uint32 priority;
|
uint32 src_ip = 0;
|
||||||
timeval timestamp;
|
uint32 dst_ip = 0;
|
||||||
|
uint16 src_port = 0;
|
||||||
|
uint16 dst_port = 0;
|
||||||
|
uint32 priority = 0;
|
||||||
|
timeval timestamp{};
|
||||||
|
|
||||||
virtual void build_raw_header_dump(char *buffer, uint16 seq=0xffff) const;
|
virtual void build_raw_header_dump(char *buffer, uint16 seq=0xffff) const;
|
||||||
virtual void build_header_dump(char *buffer) const;
|
virtual void build_header_dump(char *buffer) const;
|
||||||
@ -40,11 +52,11 @@ public:
|
|||||||
|
|
||||||
void setSrcInfo(uint32 sip, uint16 sport) { src_ip=sip; src_port=sport; }
|
void setSrcInfo(uint32 sip, uint16 sport) { src_ip=sip; src_port=sport; }
|
||||||
void setDstInfo(uint32 dip, uint16 dport) { dst_ip=dip; dst_port=dport; }
|
void setDstInfo(uint32 dip, uint16 dport) { dst_ip=dip; dst_port=dport; }
|
||||||
void setTimeInfo(uint32 ts_sec, uint32 ts_usec) { timestamp.tv_sec=ts_sec; timestamp.tv_usec=ts_usec; }
|
void setTimeInfo(uint32 ts_sec, uint32 ts_usec) { timestamp.tv_sec = ts_sec; timestamp.tv_usec = ts_usec; }
|
||||||
void copyInfo(const BasePacket *p) { src_ip=p->src_ip; src_port=p->src_port; dst_ip=p->dst_ip; dst_port=p->dst_port; timestamp.tv_sec=p->timestamp.tv_sec; timestamp.tv_usec=p->timestamp.tv_usec; }
|
void copyInfo(const BasePacket *p) { src_ip=p->src_ip; src_port=p->src_port; dst_ip=p->dst_ip; dst_port=p->dst_port; timestamp.tv_sec=p->timestamp.tv_sec; timestamp.tv_usec=p->timestamp.tv_usec; }
|
||||||
|
|
||||||
inline bool operator<(const BasePacket &rhs) {
|
inline bool operator<(const BasePacket &rhs) {
|
||||||
return (timestamp.tv_sec < rhs.timestamp.tv_sec || (timestamp.tv_sec==rhs.timestamp.tv_sec && timestamp.tv_usec < rhs.timestamp.tv_usec));
|
return (timestamp.tv_sec < rhs.timestamp.tv_sec || (timestamp.tv_sec == rhs.timestamp.tv_sec && timestamp.tv_usec < rhs.timestamp.tv_usec));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteUInt8(uint8 value) { *(uint8 *)(pBuffer + _wpos) = value; _wpos += sizeof(uint8); }
|
void WriteUInt8(uint8 value) { *(uint8 *)(pBuffer + _wpos) = value; _wpos += sizeof(uint8); }
|
||||||
@ -73,12 +85,6 @@ public:
|
|||||||
uint32 GetReadPosition() { return _rpos; }
|
uint32 GetReadPosition() { return _rpos; }
|
||||||
void SetWritePosition(uint32 Newwpos) { _wpos = Newwpos; }
|
void SetWritePosition(uint32 Newwpos) { _wpos = Newwpos; }
|
||||||
void SetReadPosition(uint32 Newrpos) { _rpos = Newrpos; }
|
void SetReadPosition(uint32 Newrpos) { _rpos = Newrpos; }
|
||||||
|
|
||||||
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);
|
extern void DumpPacketHex(const BasePacket* app);
|
||||||
|
|||||||
@ -31,9 +31,19 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
EQPacket::EQPacket(EmuOpcode op, const unsigned char *buf, uint32 len)
|
EQPacket::EQPacket()
|
||||||
: BasePacket(buf, len),
|
{
|
||||||
emu_opcode(op)
|
}
|
||||||
|
|
||||||
|
EQPacket::EQPacket(EmuOpcode op, const unsigned char *buf, size_t len)
|
||||||
|
: BasePacket(buf, len)
|
||||||
|
, emu_opcode(op)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EQPacket::EQPacket(EmuOpcode opcode, SerializeBuffer&& buf)
|
||||||
|
: BasePacket(std::move(buf))
|
||||||
|
, emu_opcode(opcode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,17 +370,16 @@ EQRawApplicationPacket::EQRawApplicationPacket(const unsigned char *buf, const u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DumpPacket(const EQApplicationPacket* app, bool iShowInfo) {
|
void DumpPacket(const EQApplicationPacket* app, bool iShowInfo)
|
||||||
|
{
|
||||||
if (iShowInfo) {
|
if (iShowInfo) {
|
||||||
std::cout << "Dumping Applayer: 0x" << std::hex << std::setfill('0') << std::setw(4) << app->GetOpcode() << std::dec;
|
printf("Dumping Applayer: 0x%04x size: %u", app->GetOpcode(), app->size);
|
||||||
std::cout << " size:" << app->size << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DumpPacketHex(app->pBuffer, app->size);
|
DumpPacketHex(app->pBuffer, app->size);
|
||||||
// DumpPacketAscii(app->pBuffer, app->size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DumpPacketToString(const EQApplicationPacket* app){
|
std::string DumpPacketToString(const EQApplicationPacket* app)
|
||||||
std::ostringstream out;
|
{
|
||||||
out << DumpPacketHexToString(app->pBuffer, app->size);
|
return DumpPacketHexToString(app->pBuffer, app->size);
|
||||||
return out.str();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,8 +28,15 @@
|
|||||||
#include "common/emu_opcodes.h"
|
#include "common/emu_opcodes.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class EQPacket : public BasePacket {
|
class EQPacket : public BasePacket
|
||||||
|
{
|
||||||
friend class EQStream;
|
friend class EQStream;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
EQPacket();
|
||||||
|
EQPacket(EmuOpcode opcode, const unsigned char* buf, size_t len);
|
||||||
|
EQPacket(EmuOpcode opcode, SerializeBuffer&& buf);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~EQPacket() {}
|
virtual ~EQPacket() {}
|
||||||
|
|
||||||
@ -41,19 +48,12 @@ public:
|
|||||||
virtual void DumpRawHeaderNoTime(uint16 seq=0xffff, FILE *to = stdout) const;
|
virtual void DumpRawHeaderNoTime(uint16 seq=0xffff, FILE *to = stdout) const;
|
||||||
|
|
||||||
void SetOpcode(EmuOpcode op) { emu_opcode = op; }
|
void SetOpcode(EmuOpcode op) { emu_opcode = op; }
|
||||||
const EmuOpcode GetOpcode() const { return(emu_opcode); }
|
EmuOpcode GetOpcode() const { return(emu_opcode); }
|
||||||
// const char *GetOpcodeName() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//this is just a cache so we dont look it up several times on Get()
|
//this is just a cache so we dont look it up several times on Get()
|
||||||
//and it is mutable so we can store the cached copy even on a const object
|
//and it is mutable so we can store the cached copy even on a const object
|
||||||
EmuOpcode emu_opcode;
|
EmuOpcode emu_opcode = OP_Unknown;
|
||||||
|
|
||||||
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; }
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class EQRawApplicationPacket;
|
class EQRawApplicationPacket;
|
||||||
@ -90,19 +90,43 @@ protected:
|
|||||||
uint16 opcode;
|
uint16 opcode;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EQApplicationPacket : public EQPacket {
|
class EQApplicationPacket : public EQPacket
|
||||||
|
{
|
||||||
friend class EQStream;
|
friend class EQStream;
|
||||||
|
|
||||||
|
public:
|
||||||
|
EQApplicationPacket()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EQApplicationPacket(EmuOpcode op)
|
||||||
|
: EQPacket(op, nullptr, 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EQApplicationPacket(EmuOpcode op, size_t len)
|
||||||
|
: EQPacket(op, nullptr, len)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
EQApplicationPacket(EmuOpcode op, const unsigned char* buf, size_t len)
|
||||||
|
: EQPacket(op, buf, len)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EQApplicationPacket(EmuOpcode op, SerializeBuffer&& buf)
|
||||||
|
: EQPacket(op, std::move(buf))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
EQApplicationPacket(const EQApplicationPacket& p)
|
||||||
|
: EQPacket(p.emu_opcode, p.pBuffer, p.size)
|
||||||
|
, app_opcode_size(p.app_opcode_size)
|
||||||
|
, opcode_bypass(p.opcode_bypass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EQApplicationPacket() : EQPacket(OP_Unknown, nullptr, 0), opcode_bypass(0)
|
|
||||||
{ app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; }
|
|
||||||
EQApplicationPacket(const EmuOpcode op) : EQPacket(op, nullptr, 0), opcode_bypass(0)
|
|
||||||
{ app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; }
|
|
||||||
EQApplicationPacket(const EmuOpcode op, const uint32 len) : EQPacket(op, nullptr, len), opcode_bypass(0)
|
|
||||||
{ 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);
|
bool combine(const EQApplicationPacket *rhs);
|
||||||
uint32 serialize (uint16 opcode, unsigned char *dest) const;
|
uint32 serialize (uint16 opcode, unsigned char *dest) const;
|
||||||
uint32 Size() const { return size+app_opcode_size; }
|
uint32 Size() const { return size+app_opcode_size; }
|
||||||
@ -119,15 +143,11 @@ public:
|
|||||||
|
|
||||||
uint16 GetProtocolOpcode() const { return protocol_opcode; }
|
uint16 GetProtocolOpcode() const { return protocol_opcode; }
|
||||||
void SetProtocolOpcode(uint16 v) { protocol_opcode = v; }
|
void SetProtocolOpcode(uint16 v) { protocol_opcode = v; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
uint16 protocol_opcode = 0;
|
||||||
uint16 protocol_opcode;
|
uint8 app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2;
|
||||||
uint8 app_opcode_size;
|
uint16 opcode_bypass = 0;
|
||||||
uint16 opcode_bypass;
|
|
||||||
private:
|
|
||||||
|
|
||||||
EQApplicationPacket(const EQApplicationPacket &p) : EQPacket(p.emu_opcode, p.pBuffer, p.size), opcode_bypass(p.opcode_bypass) { app_opcode_size = p.app_opcode_size; }
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class EQRawApplicationPacket : public EQApplicationPacket {
|
class EQRawApplicationPacket : public EQApplicationPacket {
|
||||||
|
|||||||
@ -3221,7 +3221,7 @@ namespace RoF
|
|||||||
|
|
||||||
buf.WriteString(new_message);
|
buf.WriteString(new_message);
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
dest->FastQueuePacket(&outapp, ack_req);
|
dest->FastQueuePacket(&outapp, ack_req);
|
||||||
delete in;
|
delete in;
|
||||||
|
|||||||
@ -689,7 +689,7 @@ namespace RoF2
|
|||||||
EQApplicationPacket *outapp = nullptr;
|
EQApplicationPacket *outapp = nullptr;
|
||||||
if (eq->bufffade == 1)
|
if (eq->bufffade == 1)
|
||||||
{
|
{
|
||||||
outapp = new EQApplicationPacket(OP_BuffCreate, 29);
|
outapp = new EQApplicationPacket(OP_BuffCreate, 29u);
|
||||||
outapp->WriteUInt32(emu->entityid);
|
outapp->WriteUInt32(emu->entityid);
|
||||||
outapp->WriteUInt32(0); // tic timer
|
outapp->WriteUInt32(0); // tic timer
|
||||||
outapp->WriteUInt8(0); // Type of OP_BuffCreate packet ?
|
outapp->WriteUInt8(0); // Type of OP_BuffCreate packet ?
|
||||||
@ -753,7 +753,7 @@ namespace RoF2
|
|||||||
ar(bl);
|
ar(bl);
|
||||||
|
|
||||||
//packet size
|
//packet size
|
||||||
auto packet_size = bl.item_name.length() + 1 + 34;
|
size_t packet_size = bl.item_name.length() + 1 + 34;
|
||||||
for (auto const &b: bl.trade_items) {
|
for (auto const &b: bl.trade_items) {
|
||||||
packet_size += b.item_name.length() + 1;
|
packet_size += b.item_name.length() + 1;
|
||||||
packet_size += 12;
|
packet_size += 12;
|
||||||
@ -1622,7 +1622,7 @@ namespace RoF2
|
|||||||
//Log.LogDebugType(Logs::General, Logs::Netcode, "[ERROR] Yourname is %s", gu2->yourname);
|
//Log.LogDebugType(Logs::General, Logs::Netcode, "[ERROR] Yourname is %s", gu2->yourname);
|
||||||
|
|
||||||
int MemberCount = 1;
|
int MemberCount = 1;
|
||||||
int PacketLength = 8 + strlen(gu2->leadersname) + 1 + 22 + strlen(gu2->yourname) + 1;
|
uint32 PacketLength = 8 + strlen(gu2->leadersname) + 1 + 22 + strlen(gu2->yourname) + 1;
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i)
|
for (int i = 0; i < 5; ++i)
|
||||||
{
|
{
|
||||||
@ -2207,7 +2207,7 @@ namespace RoF2
|
|||||||
|
|
||||||
char *Buffer = (char *)in->pBuffer;
|
char *Buffer = (char *)in->pBuffer;
|
||||||
|
|
||||||
int PacketSize = sizeof(structs::MercenaryMerchantList_Struct) - 4 + emu->MercTypeCount * 4;
|
uint32 PacketSize = sizeof(structs::MercenaryMerchantList_Struct) - 4 + emu->MercTypeCount * 4;
|
||||||
PacketSize += (sizeof(structs::MercenaryListEntry_Struct) - sizeof(structs::MercenaryStance_Struct)) * emu->MercCount;
|
PacketSize += (sizeof(structs::MercenaryListEntry_Struct) - sizeof(structs::MercenaryStance_Struct)) * emu->MercCount;
|
||||||
|
|
||||||
uint32 r;
|
uint32 r;
|
||||||
@ -3820,7 +3820,7 @@ namespace RoF2
|
|||||||
|
|
||||||
buf.WriteString(new_message);
|
buf.WriteString(new_message);
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
dest->FastQueuePacket(&outapp, ack_req);
|
dest->FastQueuePacket(&outapp, ack_req);
|
||||||
delete in;
|
delete in;
|
||||||
@ -4599,7 +4599,7 @@ namespace RoF2
|
|||||||
int k;
|
int k;
|
||||||
for (r = 0; r < entrycount; r++, emu++) {
|
for (r = 0; r < entrycount; r++, emu++) {
|
||||||
|
|
||||||
int PacketSize = 206;
|
uint32 PacketSize = 206;
|
||||||
|
|
||||||
PacketSize += strlen(emu->name);
|
PacketSize += strlen(emu->name);
|
||||||
PacketSize += strlen(emu->lastName);
|
PacketSize += strlen(emu->lastName);
|
||||||
|
|||||||
@ -2128,7 +2128,7 @@ namespace SoD
|
|||||||
|
|
||||||
buf.WriteString(new_message);
|
buf.WriteString(new_message);
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
dest->FastQueuePacket(&outapp, ack_req);
|
dest->FastQueuePacket(&outapp, ack_req);
|
||||||
delete in;
|
delete in;
|
||||||
|
|||||||
@ -1785,7 +1785,7 @@ namespace SoF
|
|||||||
|
|
||||||
buf.WriteString(new_message);
|
buf.WriteString(new_message);
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
dest->FastQueuePacket(&outapp, ack_req);
|
dest->FastQueuePacket(&outapp, ack_req);
|
||||||
delete in;
|
delete in;
|
||||||
|
|||||||
@ -1991,7 +1991,7 @@ namespace Titanium
|
|||||||
|
|
||||||
buf.WriteString(new_message);
|
buf.WriteString(new_message);
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
dest->FastQueuePacket(&outapp, ack_req);
|
dest->FastQueuePacket(&outapp, ack_req);
|
||||||
delete in;
|
delete in;
|
||||||
|
|||||||
@ -2711,7 +2711,7 @@ namespace UF
|
|||||||
|
|
||||||
buf.WriteString(new_message);
|
buf.WriteString(new_message);
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
dest->FastQueuePacket(&outapp, ack_req);
|
dest->FastQueuePacket(&outapp, ack_req);
|
||||||
delete in;
|
delete in;
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
class SerializeBuffer
|
class SerializeBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SerializeBuffer() : m_buffer(nullptr), m_capacity(0), m_pos(0) {}
|
SerializeBuffer() = default;
|
||||||
|
|
||||||
explicit SerializeBuffer(size_t size) : m_capacity(size), m_pos(0)
|
explicit SerializeBuffer(size_t size) : m_capacity(size), m_pos(0)
|
||||||
{
|
{
|
||||||
@ -35,8 +35,10 @@ public:
|
|||||||
memset(m_buffer, 0, size);
|
memset(m_buffer, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
SerializeBuffer(const SerializeBuffer &rhs)
|
SerializeBuffer(const SerializeBuffer& rhs)
|
||||||
: m_buffer(new unsigned char[rhs.m_capacity]), m_capacity(rhs.m_capacity), m_pos(rhs.m_pos)
|
: m_buffer(new unsigned char[rhs.m_capacity])
|
||||||
|
, m_capacity(rhs.m_capacity)
|
||||||
|
, m_pos(rhs.m_pos)
|
||||||
{
|
{
|
||||||
memcpy(m_buffer, rhs.m_buffer, rhs.m_capacity);
|
memcpy(m_buffer, rhs.m_buffer, rhs.m_capacity);
|
||||||
}
|
}
|
||||||
@ -53,30 +55,31 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SerializeBuffer(SerializeBuffer &&rhs) : m_buffer(rhs.m_buffer), m_capacity(rhs.m_capacity), m_pos(rhs.m_pos)
|
SerializeBuffer(SerializeBuffer&& rhs)
|
||||||
|
: m_buffer(std::exchange(rhs.m_buffer, nullptr))
|
||||||
|
, m_capacity(std::exchange(rhs.m_capacity, 0))
|
||||||
|
, m_pos(std::exchange(rhs.m_pos, 0))
|
||||||
{
|
{
|
||||||
rhs.m_buffer = nullptr;
|
|
||||||
rhs.m_capacity = 0;
|
|
||||||
rhs.m_pos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SerializeBuffer &operator=(SerializeBuffer &&rhs)
|
SerializeBuffer& operator=(SerializeBuffer&& rhs)
|
||||||
|
{
|
||||||
|
if (this != &rhs)
|
||||||
{
|
{
|
||||||
if (this != &rhs) {
|
|
||||||
delete[] m_buffer;
|
delete[] m_buffer;
|
||||||
|
|
||||||
m_buffer = rhs.m_buffer;
|
m_buffer = std::exchange(rhs.m_buffer, nullptr);
|
||||||
m_capacity = rhs.m_capacity;
|
m_capacity = std::exchange(rhs.m_capacity, 0);
|
||||||
m_pos = rhs.m_pos;
|
m_pos = std::exchange(rhs.m_pos, 0);
|
||||||
|
|
||||||
rhs.m_buffer = nullptr;
|
|
||||||
rhs.m_capacity = 0;
|
|
||||||
rhs.m_pos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~SerializeBuffer() { delete[] m_buffer; }
|
~SerializeBuffer()
|
||||||
|
{
|
||||||
|
delete[] m_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
void WriteUInt8(uint8_t v)
|
void WriteUInt8(uint8_t v)
|
||||||
{
|
{
|
||||||
@ -209,7 +212,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
void Grow(size_t new_size);
|
void Grow(size_t new_size);
|
||||||
void Reset();
|
void Reset();
|
||||||
unsigned char *m_buffer;
|
|
||||||
size_t m_capacity;
|
unsigned char* m_buffer = nullptr;
|
||||||
size_t m_pos;
|
size_t m_capacity = 0;
|
||||||
|
size_t m_pos = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -389,35 +389,31 @@ enum {
|
|||||||
class ServerPacket
|
class ServerPacket
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~ServerPacket() { safe_delete_array(pBuffer); }
|
~ServerPacket()
|
||||||
ServerPacket(uint16 in_opcode = 0, uint32 in_size = 0) {
|
{
|
||||||
this->compressed = false;
|
safe_delete_array(pBuffer);
|
||||||
size = in_size;
|
|
||||||
opcode = in_opcode;
|
|
||||||
if (size == 0) {
|
|
||||||
pBuffer = 0;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
ServerPacket(uint16 in_opcode = 0, size_t in_size = 0)
|
||||||
|
: size(static_cast<uint32>(in_size))
|
||||||
|
, opcode(in_opcode)
|
||||||
|
{
|
||||||
|
if (size != 0)
|
||||||
|
{
|
||||||
pBuffer = new uchar[size];
|
pBuffer = new uchar[size];
|
||||||
memset(pBuffer, 0, size);
|
memset(pBuffer, 0, size);
|
||||||
}
|
}
|
||||||
_wpos = 0;
|
|
||||||
_rpos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerPacket(uint16 in_opcode, const EQ::Net::Packet &p) {
|
ServerPacket(uint16 in_opcode, const EQ::Net::Packet& p)
|
||||||
this->compressed = false;
|
: size(static_cast<uint32>(p.Length()))
|
||||||
size = (uint32)p.Length();
|
, opcode(in_opcode)
|
||||||
opcode = in_opcode;
|
{
|
||||||
if (size == 0) {
|
if (size != 0)
|
||||||
pBuffer = 0;
|
{
|
||||||
}
|
|
||||||
else {
|
|
||||||
pBuffer = new uchar[size];
|
pBuffer = new uchar[size];
|
||||||
memcpy(pBuffer, p.Data(), size);
|
memcpy(pBuffer, p.Data(), size);
|
||||||
}
|
}
|
||||||
_wpos = 0;
|
|
||||||
_rpos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerPacket* Copy() {
|
ServerPacket* Copy() {
|
||||||
@ -447,14 +443,14 @@ public:
|
|||||||
void ReadSkipBytes(uint32 count) { _rpos += count; }
|
void ReadSkipBytes(uint32 count) { _rpos += count; }
|
||||||
void SetReadPosition(uint32 Newrpos) { _rpos = Newrpos; }
|
void SetReadPosition(uint32 Newrpos) { _rpos = Newrpos; }
|
||||||
|
|
||||||
uint32 size;
|
uint32 size = 0;
|
||||||
uint16 opcode;
|
uint16 opcode = 0;
|
||||||
uchar* pBuffer;
|
uchar* pBuffer = nullptr;
|
||||||
uint32 _wpos;
|
uint32 _wpos = 0;
|
||||||
uint32 _rpos;
|
uint32 _rpos = 0;
|
||||||
bool compressed;
|
bool compressed = false;
|
||||||
uint32 InflatedSize;
|
uint32 InflatedSize = 0;
|
||||||
uint32 destination;
|
uint32 destination = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(push)
|
#pragma pack(push)
|
||||||
@ -989,11 +985,12 @@ struct LauncherConnectInfo {
|
|||||||
char name[64];
|
char name[64];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
enum ZoneRequestCommands {
|
||||||
ZR_Start,
|
ZR_Start,
|
||||||
ZR_Restart,
|
ZR_Restart,
|
||||||
ZR_Stop
|
ZR_Stop
|
||||||
} ZoneRequestCommands;
|
};
|
||||||
|
|
||||||
struct LauncherZoneRequest {
|
struct LauncherZoneRequest {
|
||||||
uint8 command;
|
uint8 command;
|
||||||
char short_name[33];
|
char short_name[33];
|
||||||
|
|||||||
@ -547,7 +547,7 @@ void Client::SendExpansionPacketData(PlayerLoginReply &plrs)
|
|||||||
buf.WriteInt32(0xFFFFFFFF);
|
buf.WriteInt32(0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto out = std::make_unique<EQApplicationPacket>(OP_LoginExpansionPacketData, buf);
|
auto out = std::make_unique<EQApplicationPacket>(OP_LoginExpansionPacketData, std::move(buf));
|
||||||
m_connection->QueuePacket(out.get());
|
m_connection->QueuePacket(out.get());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,7 +153,7 @@ std::unique_ptr<EQApplicationPacket> WorldServerManager::CreateServerListPacket(
|
|||||||
s->SerializeForClientServerList(buf, use_local_ip, client->GetClientVersion());
|
s->SerializeForClientServerList(buf, use_local_ip, client->GetClientVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_unique<EQApplicationPacket>(OP_ServerListResponse, buf);
|
return std::make_unique<EQApplicationPacket>(OP_ServerListResponse, std::move(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldServerManager::SendUserLoginToWorldRequest(
|
void WorldServerManager::SendUserLoginToWorldRequest(
|
||||||
|
|||||||
@ -1784,7 +1784,7 @@ void Client::Message(uint32 type, const char* message, ...) {
|
|||||||
buf.WriteInt32(0);
|
buf.WriteInt32(0);
|
||||||
buf.WriteString(buffer);
|
buf.WriteString(buffer);
|
||||||
|
|
||||||
auto app = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto app = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
FastQueuePacket(&app);
|
FastQueuePacket(&app);
|
||||||
|
|
||||||
@ -1813,7 +1813,7 @@ void Client::FilteredMessage(Mob *sender, uint32 type, eqFilterType filter, cons
|
|||||||
buf.WriteInt32(0);
|
buf.WriteInt32(0);
|
||||||
buf.WriteString(buffer);
|
buf.WriteString(buffer);
|
||||||
|
|
||||||
auto app = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto app = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
FastQueuePacket(&app);
|
FastQueuePacket(&app);
|
||||||
|
|
||||||
@ -3869,7 +3869,7 @@ void Client::MessageString(uint32 type, uint32 string_id, const char* message1,
|
|||||||
|
|
||||||
buf.WriteInt8(0); // prevent oob in packet translation, maybe clean that up sometime
|
buf.WriteInt8(0); // prevent oob in packet translation, maybe clean that up sometime
|
||||||
|
|
||||||
auto outapp = std::make_unique<EQApplicationPacket>(OP_FormattedMessage, buf);
|
auto outapp = std::make_unique<EQApplicationPacket>(OP_FormattedMessage, std::move(buf));
|
||||||
|
|
||||||
if (distance > 0)
|
if (distance > 0)
|
||||||
entity_list.QueueCloseClients(this, outapp.get(), false, distance);
|
entity_list.QueueCloseClients(this, outapp.get(), false, distance);
|
||||||
@ -3987,7 +3987,7 @@ void Client::FilteredMessageString(Mob *sender, uint32 type, eqFilterType filter
|
|||||||
|
|
||||||
buf.WriteInt8(0); // prevent oob in packet translation, maybe clean that up sometime
|
buf.WriteInt8(0); // prevent oob in packet translation, maybe clean that up sometime
|
||||||
|
|
||||||
auto outapp = std::make_unique<EQApplicationPacket>(OP_FormattedMessage, buf);
|
auto outapp = std::make_unique<EQApplicationPacket>(OP_FormattedMessage, std::move(buf));
|
||||||
|
|
||||||
QueuePacket(outapp.get());
|
QueuePacket(outapp.get());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4437,7 +4437,7 @@ void EntityList::QuestJournalledSayClose(
|
|||||||
buf.WriteString(message);
|
buf.WriteString(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
|
||||||
|
|
||||||
// client only bothers logging if target spawn ID matches, safe to send to everyone
|
// client only bothers logging if target spawn ID matches, safe to send to everyone
|
||||||
QueueCloseClients(sender, outapp, false, dist);
|
QueueCloseClients(sender, outapp, false, dist);
|
||||||
|
|||||||
@ -117,7 +117,7 @@ void SharedTaskZoneMessaging::HandleWorldMessage(ServerPacket *pack)
|
|||||||
buf.WriteInt8(m.is_leader ? 1 : 0);
|
buf.WriteInt8(m.is_leader ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto outapp = std::make_unique<EQApplicationPacket>(OP_SharedTaskMemberList, buf);
|
auto outapp = std::make_unique<EQApplicationPacket>(OP_SharedTaskMemberList, std::move(buf));
|
||||||
c->QueuePacket(outapp.get());
|
c->QueuePacket(outapp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ void SharedTaskZoneMessaging::HandleWorldMessage(ServerPacket *pack)
|
|||||||
// live sends more after the name but it might just be garbage from
|
// live sends more after the name but it might just be garbage from
|
||||||
// a re-used buffer (possibly a former name[64] buffer?)
|
// a re-used buffer (possibly a former name[64] buffer?)
|
||||||
|
|
||||||
auto outapp = std::make_unique<EQApplicationPacket>(OP_SharedTaskMemberChange, buf);
|
auto outapp = std::make_unique<EQApplicationPacket>(OP_SharedTaskMemberChange, std::move(buf));
|
||||||
c->QueuePacket(outapp.get());
|
c->QueuePacket(outapp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -858,7 +858,7 @@ void TaskManager::SendTaskSelector(Client* client, Mob* mob, const std::vector<i
|
|||||||
client->GetTaskState()->AddOffer(task_list[i], mob->GetID());
|
client->GetTaskState()->AddOffer(task_list[i], mob->GetID());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto outapp = std::make_unique<EQApplicationPacket>(OP_TaskSelectWindow, buf);
|
auto outapp = std::make_unique<EQApplicationPacket>(OP_TaskSelectWindow, std::move(buf));
|
||||||
client->QueuePacket(outapp.get());
|
client->QueuePacket(outapp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -883,7 +883,7 @@ void TaskManager::SendSharedTaskSelector(Client* client, Mob* mob, const std::ve
|
|||||||
client->GetTaskState()->AddOffer(task_id, mob->GetID());
|
client->GetTaskState()->AddOffer(task_id, mob->GetID());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto outapp = std::make_unique<EQApplicationPacket>(OP_SharedTaskSelectWindow, buf);
|
auto outapp = std::make_unique<EQApplicationPacket>(OP_SharedTaskSelectWindow, std::move(buf));
|
||||||
client->QueuePacket(outapp.get());
|
client->QueuePacket(outapp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,7 +1009,7 @@ void TaskManager::SendTaskActivityLong(
|
|||||||
|
|
||||||
activity.SerializeObjective(buf, client->ClientVersion(), done_count);
|
activity.SerializeObjective(buf, client->ClientVersion(), done_count);
|
||||||
|
|
||||||
auto outapp = std::make_unique<EQApplicationPacket>(OP_TaskActivity, buf);
|
auto outapp = std::make_unique<EQApplicationPacket>(OP_TaskActivity, std::move(buf));
|
||||||
client->QueuePacket(outapp.get());
|
client->QueuePacket(outapp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -550,7 +550,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
|
|||||||
SerializeBuffer buf(100);
|
SerializeBuffer buf(100);
|
||||||
buf.WriteString(smotd->motd);
|
buf.WriteString(smotd->motd);
|
||||||
|
|
||||||
auto outapp = std::make_unique<EQApplicationPacket>(OP_MOTD, buf);
|
auto outapp = std::make_unique<EQApplicationPacket>(OP_MOTD, std::move(buf));
|
||||||
|
|
||||||
entity_list.QueueClients(0, outapp.get());
|
entity_list.QueueClients(0, outapp.get());
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user