-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding network msg to network msg #4878
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
|
||
#include <boost/locale.hpp> | ||
|
||
static constexpr size_t MAX_BODY_SIZE = 8192; | ||
|
||
std::string NetworkMessage::getString(uint16_t stringLen /* = 0*/) | ||
{ | ||
if (stringLen == 0) { | ||
|
@@ -42,7 +44,7 @@ void NetworkMessage::addString(std::string_view value) | |
std::string latin1Str = boost::locale::conv::from_utf<char>(value.data(), value.data() + value.size(), "ISO-8859-1", | ||
boost::locale::conv::skip); | ||
size_t stringLen = latin1Str.size(); | ||
if (!canAdd(stringLen + 2) || stringLen > 8192) { | ||
if (!canAdd(stringLen + 2) || stringLen > MAX_BODY_SIZE) { | ||
return; | ||
} | ||
|
||
|
@@ -61,7 +63,18 @@ void NetworkMessage::addDouble(double value, uint8_t precision /* = 2*/) | |
|
||
void NetworkMessage::addBytes(const char* bytes, size_t size) | ||
{ | ||
if (!canAdd(size) || size > 8192) { | ||
if (!canAdd(size) || size > MAX_BODY_SIZE) { | ||
return; | ||
} | ||
|
||
std::memcpy(buffer.data() + info.position, bytes, size); | ||
info.position += size; | ||
info.length += size; | ||
} | ||
|
||
void NetworkMessage::addBytes(const uint8_t* bytes, size_t size) | ||
{ | ||
if (!canAdd(size) || size > MAX_BODY_SIZE) { | ||
return; | ||
} | ||
|
||
|
@@ -191,3 +204,12 @@ void NetworkMessage::addItem(const Item* item) | |
} | ||
|
||
void NetworkMessage::addItemId(uint16_t itemId) { add<uint16_t>(Item::items[itemId].clientId); } | ||
|
||
void NetworkMessage::addNetworkMessage(const NetworkMessage& networkMsg) | ||
{ | ||
if (!canAdd(networkMsg.getLength())) { | ||
return; | ||
} | ||
|
||
addBytes(networkMsg.getBuffer() + INITIAL_BUFFER_POSITION, networkMsg.getLength()); | ||
} | ||
Comment on lines
+208
to
+215
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a suggestion, you can abbreviate |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ class NetworkMessage | |
} | ||
|
||
void addBytes(const char* bytes, size_t size); | ||
void addBytes(const uint8_t* bytes, size_t size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to avoid reinterpret_cast<const char*> |
||
void addPaddingBytes(size_t n); | ||
|
||
void addString(std::string_view value); | ||
|
@@ -111,6 +112,7 @@ class NetworkMessage | |
void addItem(uint16_t id, uint8_t count); | ||
void addItem(const Item* item); | ||
void addItemId(uint16_t itemId); | ||
void addNetworkMessage(const NetworkMessage& networkMsg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion above |
||
|
||
MsgSize_t getLength() const { return info.length; } | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we always return
true
, even when there’s no space in the msg body