Skip to content

Commit

Permalink
Make OutputMessage::addRawString available in Lua (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
divinity76 authored Sep 14, 2024
1 parent e6861d7 commit dab86e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/framework/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<OutputMessage>("addU32", &OutputMessage::addU32);
g_lua.bindClassMemberFunction<OutputMessage>("addU64", &OutputMessage::addU64);
g_lua.bindClassMemberFunction<OutputMessage>("addString", &OutputMessage::addString);
g_lua.bindClassMemberFunction<OutputMessage>("addRawString", &OutputMessage::addRawString);
g_lua.bindClassMemberFunction<OutputMessage>("addPaddingBytes", &OutputMessage::addPaddingBytes);
g_lua.bindClassMemberFunction<OutputMessage>("encryptRsa", &OutputMessage::encryptRsa);
g_lua.bindClassMemberFunction<OutputMessage>("getMessageSize", &OutputMessage::getMessageSize);
Expand Down
11 changes: 11 additions & 0 deletions src/framework/net/outputmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/framework/net/outputmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit dab86e6

Please sign in to comment.