From 40a764a9a3e4e4027acac344adfdcf53158193d7 Mon Sep 17 00:00:00 2001 From: d1str4ught <> Date: Sat, 23 Aug 2025 20:48:26 +0200 Subject: [PATCH] small fix for buffer resize --- src/db/PeerBase.cpp | 14 +++++++------- src/db/PeerBase.h | 8 ++++---- src/game/protocol.h | 40 ++++++++++++++++++++-------------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/db/PeerBase.cpp b/src/db/PeerBase.cpp index 0907302..938466c 100644 --- a/src/db/PeerBase.cpp +++ b/src/db/PeerBase.cpp @@ -95,7 +95,7 @@ void CPeerBase::Close() OnClose(); } -void CPeerBase::EncodeBYTE(BYTE b) +void CPeerBase::EncodeBYTE(uint8_t b) { if (!m_outBuffer) { @@ -103,11 +103,11 @@ void CPeerBase::EncodeBYTE(BYTE b) return; } - buffer_write(m_outBuffer, &b, 1); + buffer_write(m_outBuffer, &b, sizeof(uint8_t)); fdwatch_add_fd(m_fdWatcher, m_fd, this, FDW_WRITE, true); } -void CPeerBase::EncodeWORD(WORD w) +void CPeerBase::EncodeWORD(uint16_t w) { if (!m_outBuffer) { @@ -115,11 +115,11 @@ void CPeerBase::EncodeWORD(WORD w) return; } - buffer_write(m_outBuffer, &w, 2); + buffer_write(m_outBuffer, &w, sizeof(uint16_t)); fdwatch_add_fd(m_fdWatcher, m_fd, this, FDW_WRITE, true); } -void CPeerBase::EncodeDWORD(DWORD dw) +void CPeerBase::EncodeDWORD(uint32_t dw) { if (!m_outBuffer) { @@ -127,11 +127,11 @@ void CPeerBase::EncodeDWORD(DWORD dw) return; } - buffer_write(m_outBuffer, &dw, 4); + buffer_write(m_outBuffer, &dw, sizeof(uint32_t)); fdwatch_add_fd(m_fdWatcher, m_fd, this, FDW_WRITE, true); } -void CPeerBase::Encode(const void* data, DWORD size) +void CPeerBase::Encode(const void* data, uint32_t size) { if (!m_outBuffer) { diff --git a/src/db/PeerBase.h b/src/db/PeerBase.h index 2796d6d..95f5c9d 100644 --- a/src/db/PeerBase.h +++ b/src/db/PeerBase.h @@ -33,10 +33,10 @@ class CPeerBase : public CNetBase socket_t GetFd() { return m_fd; } - void EncodeBYTE(BYTE b); - void EncodeWORD(WORD w); - void EncodeDWORD(DWORD dw); - void Encode(const void* data, DWORD size); + void EncodeBYTE(uint8_t b); + void EncodeWORD(uint16_t w); + void EncodeDWORD(uint32_t dw); + void Encode(const void* data, uint32_t size); int Send(); int Recv(); diff --git a/src/game/protocol.h b/src/game/protocol.h index 732863e..78c7836 100644 --- a/src/game/protocol.h +++ b/src/game/protocol.h @@ -1,40 +1,42 @@ -#ifndef __PROTOCOL_H__ -#define __PROTOCOL_H__ +#pragma once +#include +#include +#include "libthecore/buffer.h" -inline const char *encode_byte(char ind) +inline const char *encode_byte(uint8_t ind) { - static char a[8]; - *((char *) a) = ind; + static char a[1]; + *((uint8_t*)a) = ind; return (a); } -inline const char *encode_2bytes(sh_int ind) +inline const char *encode_2bytes(uint16_t ind) { - static char a[8]; - *((sh_int *) a) = ind; + static char a[2]; + *((uint16_t*)a) = ind; return (a); } -inline const char *encode_4bytes(int ind) +inline const char *encode_4bytes(uint32_t ind) { - static char a[8]; - *((int *) a) = ind; + static char a[4]; + *((uint32_t*)a) = ind; return (a); } -inline BYTE decode_byte(const void * a) +inline uint8_t decode_byte(const void * a) { - return (*(BYTE *) a); + return (*(uint8_t*)a); } -inline WORD decode_2bytes(const void * a) +inline uint16_t decode_2bytes(const void * a) { - return (*((WORD *) a)); + return (*((uint16_t*)a)); } -inline INT decode_4bytes(const void *a) +inline uint32_t decode_4bytes(const void *a) { - return (*((INT *) a)); + return (*((uint32_t*)a)); } #define packet_encode(buf, data, len) __packet_encode(buf, data, len, __FILE__, __LINE__) @@ -42,7 +44,7 @@ inline INT decode_4bytes(const void *a) //#define DEFAULT_PACKET_BUFFER_SIZE 32768 #define DEFAULT_PACKET_BUFFER_SIZE 65536 -inline bool __packet_encode(LPBUFFER pbuf, const void * data, int length, const char * file, int line) +inline bool __packet_encode(LPBUFFER& pbuf, const void * data, int length, const char * file, int line) { assert(NULL != pbuf); assert(NULL != data); @@ -57,5 +59,3 @@ inline bool __packet_encode(LPBUFFER pbuf, const void * data, int length, const buffer_write(pbuf, data, length); return true; } - -#endif