From dab86e610991092fe8b2471f7de55a7c986b3cd2 Mon Sep 17 00:00:00 2001 From: divinity76 Date: Sat, 14 Sep 2024 17:26:54 +0200 Subject: [PATCH] Make OutputMessage::addRawString available in Lua (#1218) --- src/framework/luafunctions.cpp | 1 + src/framework/net/outputmessage.cpp | 11 +++++++++++ src/framework/net/outputmessage.h | 1 + 3 files changed, 13 insertions(+) diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index eb4b0bd19..fe347c131 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -818,6 +818,7 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("addU32", &OutputMessage::addU32); g_lua.bindClassMemberFunction("addU64", &OutputMessage::addU64); g_lua.bindClassMemberFunction("addString", &OutputMessage::addString); + g_lua.bindClassMemberFunction("addRawString", &OutputMessage::addRawString); g_lua.bindClassMemberFunction("addPaddingBytes", &OutputMessage::addPaddingBytes); g_lua.bindClassMemberFunction("encryptRsa", &OutputMessage::encryptRsa); g_lua.bindClassMemberFunction("getMessageSize", &OutputMessage::getMessageSize); diff --git a/src/framework/net/outputmessage.cpp b/src/framework/net/outputmessage.cpp index c0e475e13..688491193 100644 --- a/src/framework/net/outputmessage.cpp +++ b/src/framework/net/outputmessage.cpp @@ -89,6 +89,17 @@ void OutputMessage::addString(const std::string& buffer) m_messageSize += len; } +void OutputMessage::addRawString(const std::string& buffer) +{ + int len = buffer.length(); + if (len > MAX_STRING_LENGTH) + throw stdext::exception(stdext::format("string length > %d", MAX_STRING_LENGTH)); + checkWrite(len); + memcpy((char*)(m_buffer + m_writePos), buffer.c_str(), len); + m_writePos += len; + m_messageSize += len; +} + void OutputMessage::addPaddingBytes(int bytes, uint8 byte) { if(bytes <= 0) diff --git a/src/framework/net/outputmessage.h b/src/framework/net/outputmessage.h index 3dcc53312..3a66518a0 100644 --- a/src/framework/net/outputmessage.h +++ b/src/framework/net/outputmessage.h @@ -48,6 +48,7 @@ class OutputMessage : public LuaObject void addU32(uint32 value); void addU64(uint64 value); void addString(const std::string& buffer); + void addRawString(const std::string& buffer); void addPaddingBytes(int bytes, uint8 byte = 0); void encryptRsa();