From 24788099457e8ddd8ec2f409d2125d52e0ac3feb Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 14 May 2012 18:36:54 -0300 Subject: [PATCH] add lua flexibility for protocol * use shared_ptr for InputMessage and OutputMessage and bind them * allow sending network messages from lua * implement extended opcode * use own OS type for otclient to allow server side detection * fixes in input event bot protection * move RSA to input/output network messages * allow to capture opcodes before GameProtocol parsing with the event GameProtocol.onOpcode * fixes in lua std::string pop/push to allow byte buffering --- src/framework/application.cpp | 6 + src/framework/application.h | 2 + src/framework/luafunctions.cpp | 30 +- src/framework/luascript/luainterface.cpp | 14 +- src/framework/luascript/luainterface.h | 2 +- src/framework/net/declarations.h | 4 +- src/framework/net/inputmessage.cpp | 6 + src/framework/net/inputmessage.h | 35 +- src/framework/net/outputmessage.cpp | 28 +- src/framework/net/outputmessage.h | 11 +- src/framework/net/protocol.cpp | 45 +- src/framework/net/protocol.h | 23 +- src/framework/net/rsa.cpp | 124 ++--- src/framework/net/rsa.h | 17 +- src/framework/ui/uimanager.cpp | 2 - src/framework/ui/uimanager.h | 2 - src/otclient/CMakeLists.txt | 2 +- src/otclient/core/game.cpp | 3 +- src/otclient/luafunctions.cpp | 14 +- src/otclient/net/protocolcodes.h | 14 +- src/otclient/net/protocolgame.cpp | 2 +- src/otclient/net/protocolgame.h | 209 ++++--- src/otclient/net/protocolgameparse.cpp | 680 ++++++++++++----------- src/otclient/net/protocolgamesend.cpp | 553 +++++++++--------- src/otclient/net/protocollogin.cpp | 71 ++- src/otclient/net/protocollogin.h | 8 +- 26 files changed, 969 insertions(+), 938 deletions(-) diff --git a/src/framework/application.cpp b/src/framework/application.cpp index aa191ad2..46640f09 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -221,8 +221,10 @@ void Application::poll() void Application::close() { + m_onInputEvent = true; if(!g_lua.callGlobalField("g_app", "onClose")) exit(); + m_onInputEvent = false; } void Application::render() @@ -235,11 +237,15 @@ void Application::render() void Application::resize(const Size& size) { + m_onInputEvent = true; g_graphics.resize(size); g_ui.resize(size); + m_onInputEvent = false; } void Application::inputEvent(const InputEvent& event) { + m_onInputEvent = true; g_ui.inputEvent(event); + m_onInputEvent = false; } diff --git a/src/framework/application.h b/src/framework/application.h index 7870a423..b865b01a 100644 --- a/src/framework/application.h +++ b/src/framework/application.h @@ -47,6 +47,7 @@ public: bool isRunning() { return m_running; } bool isStopping() { return m_stopping; } + bool isOnInputEvent() { return m_onInputEvent; } int getFrameSleep() { return m_frameSleep; } const std::string& getName() { return m_appName; } const std::string& getVersion() { return m_appVersion; } @@ -68,6 +69,7 @@ protected: Boolean m_initialized; Boolean m_running; Boolean m_stopping; + Boolean m_onInputEvent; }; extern Application *g_app; diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 57e42459..93c6e08f 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -397,6 +397,11 @@ void Application::registerLuaFunctions() // Protocol g_lua.registerClass(); + //g_lua.bindClassMemberFunction("connect", &Protocol::connect); + g_lua.bindClassMemberFunction("disconnect", &Protocol::disconnect); + g_lua.bindClassMemberFunction("isConnected", &Protocol::isConnected); + g_lua.bindClassMemberFunction("isConnecting", &Protocol::isConnecting); + g_lua.bindClassMemberFunction("send", &Protocol::send); // Module g_lua.registerClass(); @@ -415,20 +420,31 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("isAutoLoad", &Module::isAutoLoad); g_lua.bindClassMemberFunction("getAutoLoadPriority", &Module::getAutoLoadPriority); - // network manipulation via lua is disabled for a while - /* + // InputMessage + g_lua.registerClass(); + g_lua.bindClassStaticFunction("create", []{ return InputMessagePtr(new InputMessage); }); + g_lua.bindClassMemberFunction("skipBytes", &InputMessage::skipBytes); + g_lua.bindClassMemberFunction("getU8", &InputMessage::getU8); + g_lua.bindClassMemberFunction("getU16", &InputMessage::getU16); + g_lua.bindClassMemberFunction("getU32", &InputMessage::getU32); + g_lua.bindClassMemberFunction("getU64", &InputMessage::getU64); + g_lua.bindClassMemberFunction("getString", &InputMessage::getString); + g_lua.bindClassMemberFunction("decryptRSA", &InputMessage::decryptRSA); + g_lua.bindClassMemberFunction("getReadSize", &InputMessage::getReadSize); + g_lua.bindClassMemberFunction("getUnreadSize", &InputMessage::getUnreadSize); + g_lua.bindClassMemberFunction("eof", &InputMessage::eof); + // OutputMessage g_lua.registerClass(); - g_lua.bindClassStaticFunction("new", []{ return OutputMessagePtr(new OutputMessage); }); + g_lua.bindClassStaticFunction("create", []{ return OutputMessagePtr(new OutputMessage); }); g_lua.bindClassMemberFunction("reset", &OutputMessage::reset); g_lua.bindClassMemberFunction("addU8", &OutputMessage::addU8); g_lua.bindClassMemberFunction("addU16", &OutputMessage::addU16); g_lua.bindClassMemberFunction("addU32", &OutputMessage::addU32); g_lua.bindClassMemberFunction("addU64", &OutputMessage::addU64); - g_lua.bindClassMemberFunction("addString", (void(OutputMessage::*)(const std::string&))&OutputMessage::addString); - - g_lua.bindClassStaticFunction("send", [](const ProtocolPtr proto, OutputMessagePtr msg) { proto->send(*msg.get()); }); - */ + g_lua.bindClassMemberFunction("addString", &OutputMessage::addString); + g_lua.bindClassMemberFunction("addPaddingBytes", &OutputMessage::addPaddingBytes); + g_lua.bindClassMemberFunction("encryptRSA", &OutputMessage::encryptRSA); // Application g_lua.registerStaticClass("g_app"); diff --git a/src/framework/luascript/luainterface.cpp b/src/framework/luascript/luainterface.cpp index d0c69bc2..a879a602 100644 --- a/src/framework/luascript/luainterface.cpp +++ b/src/framework/luascript/luainterface.cpp @@ -610,7 +610,7 @@ void LuaInterface::createLuaState() // load lua standard libraries luaL_openlibs(L); - + // load bit32 lib for bitwise operations luaopen_bit32(L); @@ -998,6 +998,11 @@ void LuaInterface::pushCString(const char* v) lua_pushstring(L, v); } +void LuaInterface::pushString(const std::string& v) +{ + lua_pushlstring(L, v.c_str(), v.length()); +} + void LuaInterface::pushLightUserdata(void* p) { lua_pushlightuserdata(L, p); @@ -1121,9 +1126,10 @@ std::string LuaInterface::toString(int index) { assert(hasIndex(index)); std::string str; - const char *c_str = lua_tostring(L, index); - if(c_str) - str = c_str; + size_t len; + const char *c_str = lua_tolstring(L, index, &len); + if(c_str && len > 0) + str.assign(c_str, len); return str; } diff --git a/src/framework/luascript/luainterface.h b/src/framework/luascript/luainterface.h index e731ed65..ee5b296c 100644 --- a/src/framework/luascript/luainterface.h +++ b/src/framework/luascript/luainterface.h @@ -269,7 +269,7 @@ public: void pushNumber(double v); void pushBoolean(bool v); void pushCString(const char* v); - void pushString(const std::string& v) { pushCString(v.c_str()); } + void pushString(const std::string& v); void pushLightUserdata(void* p); void pushThread(); void pushValue(int index = -1); diff --git a/src/framework/net/declarations.h b/src/framework/net/declarations.h index 55f9dd2e..6ab486b9 100644 --- a/src/framework/net/declarations.h +++ b/src/framework/net/declarations.h @@ -28,12 +28,14 @@ namespace asio = boost::asio; -class Connection; class InputMessage; class OutputMessage; +class Connection; class Protocol; class Server; +typedef std::shared_ptr InputMessagePtr; +typedef std::shared_ptr OutputMessagePtr; typedef std::shared_ptr ConnectionPtr; typedef std::weak_ptr ConnectionWeakPtr; typedef std::shared_ptr ProtocolPtr; diff --git a/src/framework/net/inputmessage.cpp b/src/framework/net/inputmessage.cpp index e0d3e8a6..b2b8ca35 100644 --- a/src/framework/net/inputmessage.cpp +++ b/src/framework/net/inputmessage.cpp @@ -21,6 +21,7 @@ */ #include "inputmessage.h" +#include "rsa.h" InputMessage::InputMessage() { @@ -106,6 +107,11 @@ std::string InputMessage::getString() return std::string(v, stringLength); } +void InputMessage::decryptRSA(int size, const std::string& p, const std::string& q, const std::string& d) +{ + RSA::decrypt((char*)m_buffer + m_readPos, size, p.c_str(), q.c_str(), d.c_str()); +} + bool InputMessage::canRead(int bytes) { if((m_readPos - m_headerPos + bytes > m_messageSize) || (m_readPos + bytes > BUFFER_MAXSIZE)) diff --git a/src/framework/net/inputmessage.h b/src/framework/net/inputmessage.h index 70047d54..f3119a41 100644 --- a/src/framework/net/inputmessage.h +++ b/src/framework/net/inputmessage.h @@ -25,8 +25,9 @@ #include "declarations.h" #include "networkexception.h" +#include -class InputMessage +class InputMessage : public LuaObject { public: enum { @@ -36,32 +37,38 @@ public: InputMessage(); - void reset(); - - void fillBuffer(uint8 *buffer, uint16 size); - uint16 readSize() { return getU16(); } - bool readChecksum(); - - void setHeaderSize(uint16 size); - void setMessageSize(uint16 size) { m_messageSize = size; } - void skipBytes(uint16 bytes) { m_readPos += bytes; } - uint8 getU8(bool peek = false); uint16 getU16(bool peek = false); uint32 getU32(bool peek = false); uint64 getU64(bool peek = false); std::string getString(); + void decryptRSA(int size, const std::string& p, const std::string& q, const std::string& d); + + int getReadSize() { return m_readPos - m_headerPos; } + int getUnreadSize() { return m_messageSize - (m_readPos - m_headerPos); } + + bool eof() { return (m_readPos - m_headerPos) >= m_messageSize; } + +protected: + void reset(); + + void fillBuffer(uint8 *buffer, uint16 size); + + void setHeaderSize(uint16 size); + void setMessageSize(uint16 size) { m_messageSize = size; } + uint8* getReadBuffer() { return m_buffer + m_readPos; } uint8* getHeaderBuffer() { return m_buffer + m_headerPos; } uint8* getDataBuffer() { return m_buffer + MAX_HEADER_SIZE; } uint16 getHeaderSize() { return (MAX_HEADER_SIZE - m_headerPos); } uint16 getMessageSize() { return m_messageSize; } - int getReadSize() { return m_readPos - m_headerPos; } - int getUnreadSize() { return m_messageSize - (m_readPos - m_headerPos); } - bool eof() { return (m_readPos - m_headerPos) >= m_messageSize; } + uint16 readSize() { return getU16(); } + bool readChecksum(); + + friend class Protocol; private: bool canRead(int bytes); diff --git a/src/framework/net/outputmessage.cpp b/src/framework/net/outputmessage.cpp index db108c81..a926b2cb 100644 --- a/src/framework/net/outputmessage.cpp +++ b/src/framework/net/outputmessage.cpp @@ -21,6 +21,7 @@ */ #include +#include "rsa.h" OutputMessage::OutputMessage() { @@ -66,20 +67,16 @@ void OutputMessage::addU64(uint64 value) m_messageSize += 8; } -void OutputMessage::addString(const char* value, int length) +void OutputMessage::addString(const std::string& buffer) { - if(length > 65535) - throw NetworkException("[OutputMessage::addString] string length > 65535"); - checkWrite(length + 2); - addU16(length); - memcpy((char*)(m_buffer + m_writePos), value, length); - m_writePos += length; - m_messageSize += length; -} - -void OutputMessage::addString(const std::string& value) -{ - addString(value.c_str(), value.length()); + int len = buffer.length(); + if(len > MAX_STRING_LENGTH) + throw NetworkException("string length > MAX_STRING_LENGTH"); + checkWrite(len + 2); + addU16(len); + memcpy((char*)(m_buffer + m_writePos), buffer.c_str(), len); + m_writePos += len; + m_messageSize += len; } void OutputMessage::addPaddingBytes(int bytes, uint8 byte) @@ -92,6 +89,11 @@ void OutputMessage::addPaddingBytes(int bytes, uint8 byte) m_messageSize += bytes; } +void OutputMessage::encryptRSA(int size, const std::string& key) +{ + RSA::encrypt((char*)m_buffer + m_writePos - size, size, key.c_str()); +} + void OutputMessage::writeChecksum() { uint32 checksum = Fw::getAdlerChecksum(m_buffer + m_headerPos, m_messageSize); diff --git a/src/framework/net/outputmessage.h b/src/framework/net/outputmessage.h index 4f3c29bd..ecf20672 100644 --- a/src/framework/net/outputmessage.h +++ b/src/framework/net/outputmessage.h @@ -27,13 +27,12 @@ #include "networkexception.h" #include -typedef std::shared_ptr OutputMessagePtr; - class OutputMessage : public LuaObject { public: enum { BUFFER_MAXSIZE = 1024, + MAX_STRING_LENGTH = 65536, MAX_HEADER_SIZE = 8 }; @@ -45,10 +44,12 @@ public: void addU16(uint16 value); void addU32(uint32 value); void addU64(uint64 value); - void addString(const char* value, int length); - void addString(const std::string& value); + void addString(const std::string& buffer); void addPaddingBytes(int bytes, uint8 byte = 0); + void encryptRSA(int size, const std::string& key); + +protected: uint8* getWriteBuffer() { return m_buffer + m_writePos; } uint8* getHeaderBuffer() { return m_buffer + m_headerPos; } uint8* getDataBuffer() { return m_buffer + MAX_HEADER_SIZE; } @@ -57,6 +58,8 @@ public: void writeChecksum(); void writeMessageSize(); + friend class Protocol; + private: bool canWrite(int bytes); void checkWrite(int bytes); diff --git a/src/framework/net/protocol.cpp b/src/framework/net/protocol.cpp index 723b8023..c6d627a5 100644 --- a/src/framework/net/protocol.cpp +++ b/src/framework/net/protocol.cpp @@ -27,6 +27,7 @@ Protocol::Protocol() { m_xteaEncryptionEnabled = false; m_checksumEnabled = false; + m_inputMessage = InputMessagePtr(new InputMessage); } Protocol::~Protocol() @@ -63,7 +64,7 @@ bool Protocol::isConnecting() return false; } -void Protocol::send(OutputMessage& outputMessage) +void Protocol::send(const OutputMessagePtr& outputMessage) { // encrypt if(m_xteaEncryptionEnabled) @@ -71,19 +72,19 @@ void Protocol::send(OutputMessage& outputMessage) // write checksum if(m_checksumEnabled) - outputMessage.writeChecksum(); + outputMessage->writeChecksum(); // wirte message size - outputMessage.writeMessageSize(); + outputMessage->writeMessageSize(); // send if(m_connection) - m_connection->write(outputMessage.getHeaderBuffer(), outputMessage.getMessageSize()); + m_connection->write(outputMessage->getHeaderBuffer(), outputMessage->getMessageSize()); } void Protocol::recv() { - m_inputMessage.reset(); + m_inputMessage->reset(); // first update message header size int headerSize = 2; // 2 bytes for message size @@ -91,7 +92,7 @@ void Protocol::recv() headerSize += 4; // 4 bytes for checksum if(m_xteaEncryptionEnabled) headerSize += 2; // 2 bytes for XTEA encrypted message size - m_inputMessage.setHeaderSize(headerSize); + m_inputMessage->setHeaderSize(headerSize); // read the first 2 bytes which contain the message size if(m_connection) @@ -101,8 +102,8 @@ void Protocol::recv() void Protocol::internalRecvHeader(uint8* buffer, uint16 size) { // read message size - m_inputMessage.fillBuffer(buffer, size); - uint16 remainingSize = m_inputMessage.readSize(); + m_inputMessage->fillBuffer(buffer, size); + uint16 remainingSize = m_inputMessage->readSize(); // read remaining message data if(m_connection) @@ -117,9 +118,9 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size) return; } - m_inputMessage.fillBuffer(buffer, size); + m_inputMessage->fillBuffer(buffer, size); - if(m_checksumEnabled && !m_inputMessage.readChecksum()) { + if(m_checksumEnabled && !m_inputMessage->readChecksum()) { logTraceError("got a network message with invalid checksum"); return; } @@ -130,8 +131,8 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size) return; } } else { - int size = m_inputMessage.getU16(); - if(size != m_inputMessage.getUnreadSize()) { + int size = m_inputMessage->getU16(); + if(size != m_inputMessage->getUnreadSize()) { logTraceError("invalid message size"); return; } @@ -150,15 +151,15 @@ void Protocol::generateXteaKey() m_xteaKey[3] = unif(eng); } -bool Protocol::xteaDecrypt(InputMessage& inputMessage) +bool Protocol::xteaDecrypt(const InputMessagePtr& inputMessage) { - uint16 encryptedSize = inputMessage.getUnreadSize(); + uint16 encryptedSize = inputMessage->getUnreadSize(); if(encryptedSize % 8 != 0) { logTraceError("invalid encrypted network message"); return false; } - uint32 *buffer = (uint32*)(inputMessage.getReadBuffer()); + uint32 *buffer = (uint32*)(inputMessage->getReadBuffer()); int readPos = 0; while(readPos < encryptedSize/4) { @@ -175,31 +176,31 @@ bool Protocol::xteaDecrypt(InputMessage& inputMessage) readPos = readPos + 2; } - uint16 decryptedSize = inputMessage.getU16() + 2; + uint16 decryptedSize = inputMessage->getU16() + 2; int sizeDelta = decryptedSize - encryptedSize; if(sizeDelta > 0 || -sizeDelta > encryptedSize) { logTraceError("invalid decrypted a network message"); return false; } - inputMessage.setMessageSize(inputMessage.getMessageSize() + sizeDelta); + inputMessage->setMessageSize(inputMessage->getMessageSize() + sizeDelta); return true; } -void Protocol::xteaEncrypt(OutputMessage& outputMessage) +void Protocol::xteaEncrypt(const OutputMessagePtr& outputMessage) { - outputMessage.writeMessageSize(); - uint16 encryptedSize = outputMessage.getMessageSize(); + outputMessage->writeMessageSize(); + uint16 encryptedSize = outputMessage->getMessageSize(); //add bytes until reach 8 multiple if((encryptedSize % 8) != 0) { uint16 n = 8 - (encryptedSize % 8); - outputMessage.addPaddingBytes(n); + outputMessage->addPaddingBytes(n); encryptedSize += n; } int readPos = 0; - uint32 *buffer = (uint32*)(outputMessage.getDataBuffer() - 2); + uint32 *buffer = (uint32*)(outputMessage->getDataBuffer() - 2); while(readPos < encryptedSize / 4) { uint32 v0 = buffer[readPos], v1 = buffer[readPos + 1]; uint32 delta = 0x61C88647; diff --git a/src/framework/net/protocol.h b/src/framework/net/protocol.h index fa07e944..2ffd249b 100644 --- a/src/framework/net/protocol.h +++ b/src/framework/net/protocol.h @@ -41,33 +41,34 @@ public: bool isConnected(); bool isConnecting(); - void send(OutputMessage& outputMessage); - void recv(); + virtual void send(const OutputMessagePtr& outputMessage); - void internalRecvHeader(uint8* buffer, uint16 size); - void internalRecvData(uint8* buffer, uint16 size); + ProtocolPtr asProtocol() { return std::static_pointer_cast(shared_from_this()); } + +protected: + void recv(); virtual void onConnect() = 0; - virtual void onRecv(InputMessage& inputMessage) = 0; + virtual void onRecv(const InputMessagePtr& inputMessage) = 0; virtual void onError(const boost::system::error_code& err) = 0; - ProtocolPtr asProtocol() { return std::static_pointer_cast(shared_from_this()); } - -protected: void enableChecksum() { m_checksumEnabled = true; } void enableXteaEncryption() { m_xteaEncryptionEnabled = true; } void generateXteaKey(); uint32 m_xteaKey[4]; - InputMessage m_inputMessage; private: - bool xteaDecrypt(InputMessage& inputMessage); - void xteaEncrypt(OutputMessage& outputMessage); + void internalRecvHeader(uint8* buffer, uint16 size); + void internalRecvData(uint8* buffer, uint16 size); + + bool xteaDecrypt(const InputMessagePtr& inputMessage); + void xteaEncrypt(const OutputMessagePtr& outputMessage); bool m_checksumEnabled; bool m_xteaEncryptionEnabled; ConnectionPtr m_connection; + InputMessagePtr m_inputMessage; }; #endif diff --git a/src/framework/net/rsa.cpp b/src/framework/net/rsa.cpp index 90a5e3c2..4f055edc 100644 --- a/src/framework/net/rsa.cpp +++ b/src/framework/net/rsa.cpp @@ -21,56 +21,12 @@ */ #include "rsa.h" +#include -Rsa::Rsa() +void RSA::encrypt(char *msg, int size, const char* key) { - m_keySet = false; - mpz_init2(m_p, 1024); - mpz_init2(m_q, 1024); - mpz_init2(m_d, 1024); - mpz_init2(m_u, 1024); - mpz_init2(m_dp, 1024); - mpz_init2(m_dq, 1024); - mpz_init2(m_mod, 1024); -} - -Rsa::~Rsa() -{ - mpz_clear(m_p); - mpz_clear(m_q); - mpz_clear(m_d); - mpz_clear(m_u); - mpz_clear(m_dp); - mpz_clear(m_dq); - mpz_clear(m_mod); -} - -void Rsa::setKey(const char* p, const char* q, const char* d) -{ - mpz_set_str(m_p, p, 10); - mpz_set_str(m_q, q, 10); - mpz_set_str(m_d, d, 10); - - mpz_t pm1,qm1; - mpz_init2(pm1,520); - mpz_init2(qm1,520); - - mpz_sub_ui(pm1, m_p, 1); - mpz_sub_ui(qm1, m_q, 1); - mpz_invert(m_u, m_p, m_q); - mpz_mod(m_dp, m_d, pm1); - mpz_mod(m_dq, m_d, qm1); - - mpz_mul(m_mod, m_p, m_q); - - mpz_clear(pm1); - mpz_clear(qm1); + assert(size <= 128); - m_keySet = true; -} - -void Rsa::encrypt(char* msg, int32_t size, const char* key) -{ mpz_t plain, c; mpz_init2(plain, 1024); mpz_init2(c, 1024); @@ -83,12 +39,12 @@ void Rsa::encrypt(char* msg, int32_t size, const char* key) mpz_init2(mod, 1024); mpz_set_str(mod, key, 10); - mpz_import(plain, 128, 1, 1, 0, 0, msg); + mpz_import(plain, size, 1, 1, 0, 0, msg); mpz_powm(c, plain, e, mod); size_t count = (mpz_sizeinbase(c, 2) + 7)/8; - memset(msg, 0, 128 - count); - mpz_export(&msg[128 - count], NULL, 1, 1, 0, 0, c); + memset(msg, 0, size - count); + mpz_export(&msg[size - count], NULL, 1, 1, 0, 0, c); mpz_clear(c); mpz_clear(plain); @@ -96,43 +52,73 @@ void Rsa::encrypt(char* msg, int32_t size, const char* key) mpz_clear(mod); } -bool Rsa::decrypt(char* msg, int32_t size) +void RSA::decrypt(char *msg, int size, const char *p, const char *q, const char *d) { - if(!m_keySet) - return false; - - mpz_t c,v1,v2,u2,tmp; + assert(size <= 128); + + mpz_t mp, mq, md, u, dp, dq, mod, c, v1, v2, u2, tmp; + mpz_init2(mp, 1024); + mpz_init2(mq, 1024); + mpz_init2(md, 1024); + mpz_init2(u, 1024); + mpz_init2(dp, 1024); + mpz_init2(dq, 1024); + mpz_init2(mod, 1024); mpz_init2(c, 1024); mpz_init2(v1, 1024); mpz_init2(v2, 1024); mpz_init2(u2, 1024); mpz_init2(tmp, 1024); - mpz_import(c, 128, 1, 1, 0, 0, msg); + mpz_set_str(mp, p, 10); + mpz_set_str(mq, q, 10); + mpz_set_str(md, d, 10); + + mpz_t pm1,qm1; + mpz_init2(pm1, 520); + mpz_init2(qm1, 520); - mpz_mod(tmp, c, m_p); - mpz_powm(v1, tmp, m_dp, m_p); - mpz_mod(tmp, c, m_q); - mpz_powm(v2, tmp, m_dq, m_q); + mpz_sub_ui(pm1, mp, 1); + mpz_sub_ui(qm1, mq, 1); + mpz_invert(u, mp, mq); + mpz_mod(dp, md, pm1); + mpz_mod(dq, md, qm1); + + mpz_mul(mod, mp, mq); + + mpz_import(c, size, 1, 1, 0, 0, msg); + + mpz_mod(tmp, c, mp); + mpz_powm(v1, tmp, dp, mp); + mpz_mod(tmp, c, mq); + mpz_powm(v2, tmp, dq, mq); mpz_sub(u2, v2, v1); - mpz_mul(tmp, u2, m_u); - mpz_mod(u2, tmp, m_q); - if(mpz_cmp_si(u2, 0) < 0){ - mpz_add(tmp, u2, m_q); - mpz_set(u2, tmp); + mpz_mul(tmp, u2, u); + mpz_mod(u2, tmp, mq); + if(mpz_cmp_si(u2, 0) < 0) { + mpz_add(tmp, u2, mq); + mpz_set(u2, tmp); } - mpz_mul(tmp, u2, m_p); + mpz_mul(tmp, u2, mp); mpz_set_ui(c, 0); mpz_add(c, v1, tmp); size_t count = (mpz_sizeinbase(c, 2) + 7)/8; - memset(msg, 0, 128 - count); - mpz_export(&msg[128 - count], NULL, 1, 1, 0, 0, c); + memset(msg, 0, size - count); + mpz_export(&msg[size - count], NULL, 1, 1, 0, 0, c); mpz_clear(c); mpz_clear(v1); mpz_clear(v2); mpz_clear(u2); mpz_clear(tmp); - return true; + mpz_clear(pm1); + mpz_clear(qm1); + mpz_clear(mp); + mpz_clear(mq); + mpz_clear(md); + mpz_clear(u); + mpz_clear(dp); + mpz_clear(dq); + mpz_clear(mod); } diff --git a/src/framework/net/rsa.h b/src/framework/net/rsa.h index 59deda24..d0a4b2a8 100644 --- a/src/framework/net/rsa.h +++ b/src/framework/net/rsa.h @@ -24,22 +24,11 @@ #define RSA_H #include -#include -class Rsa +namespace RSA { -public: - Rsa(); - ~Rsa(); - - void setKey(const char* p, const char* q, const char* d); - bool decrypt(char* msg, int32_t size); - static void encrypt(char* msg, int32_t size, const char* key); - -protected: - bool m_keySet; - - mpz_t m_p, m_q, m_u, m_d, m_dp, m_dq, m_mod; + void encrypt(char *msg, int size, const char *key); + void decrypt(char *msg, int size, const char *p, const char *q, const char *d); }; #endif \ No newline at end of file diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index f0286166..705d8629 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -63,7 +63,6 @@ void UIManager::resize(const Size& size) void UIManager::inputEvent(const InputEvent& event) { - m_isOnInputEvent = true; UIWidgetList widgetList; switch(event.type) { case Fw::KeyTextInputEvent: @@ -155,7 +154,6 @@ void UIManager::inputEvent(const InputEvent& event) default: break; }; - m_isOnInputEvent = false; } void UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos) diff --git a/src/framework/ui/uimanager.h b/src/framework/ui/uimanager.h index 9c6d1950..b949e287 100644 --- a/src/framework/ui/uimanager.h +++ b/src/framework/ui/uimanager.h @@ -62,7 +62,6 @@ public: UIWidgetPtr getPressedWidget() { return m_pressedWidget; } UIWidgetPtr getRootWidget() { return m_rootWidget; } - bool isOnInputEvent() { return m_isOnInputEvent; } bool isDrawingDebugBoxes() { return m_drawDebugBoxes; } protected: @@ -80,7 +79,6 @@ private: UIWidgetPtr m_hoveredWidget; UIWidgetPtr m_pressedWidget; Boolean m_hoverUpdateScheduled; - bool m_isOnInputEvent; Boolean m_drawDebugBoxes; std::unordered_map m_styles; }; diff --git a/src/otclient/CMakeLists.txt b/src/otclient/CMakeLists.txt index 86063f5f..1a83cd55 100644 --- a/src/otclient/CMakeLists.txt +++ b/src/otclient/CMakeLists.txt @@ -11,7 +11,7 @@ ADD_DEFINITIONS(-DPROTOCOL=${PROTOCOL}) MESSAGE(STATUS "Protocol: " ${PROTOCOL}) IF(CIPSOFT_RSA) - ADD_DEFINITIONS(-DCIPSOFT_RSA) + ADD_DEFINITIONS(-DCIPSOFT_RSA -DOSTYPE=2) MESSAGE(STATUS "RSA: CipSoft") ELSE() MESSAGE(STATUS "RSA: OTServ") diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 1dd77153..4a09e33c 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -29,6 +29,7 @@ #include "statictext.h" #include #include +#include #include #include @@ -993,7 +994,7 @@ bool Game::checkBotProtection() #ifdef BOT_PROTECTION // accepts calls comming from a stacktrace containing only C++ functions, // if the stacktrace contains a lua function, then only accept if the engine is processing an input event - if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) { + if(g_lua.isInCppCallback() && !g_app->isOnInputEvent()) { logError(g_lua.traceback("caught a lua call to a bot protected game function, the call was canceled")); return false; } diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 1db624d6..a739e29f 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -175,6 +175,19 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("cancelLogin", &ProtocolLogin::cancelLogin); g_lua.registerClass(); + g_lua.bindClassStaticFunction("create", []{ return ProtocolGamePtr(new ProtocolGame); }); + g_lua.bindClassMemberFunction("login", &ProtocolGame::login); + g_lua.bindClassMemberFunction("send", &ProtocolGame::send); + g_lua.bindClassMemberFunction("sendExtendedOpcode", &ProtocolGame::sendExtendedOpcode); + g_lua.bindClassMemberFunction("addPosition", &ProtocolGame::addPosition); + g_lua.bindClassMemberFunction("setMapDescription", &ProtocolGame::setMapDescription); + g_lua.bindClassMemberFunction("setFloorDescription", &ProtocolGame::setFloorDescription); + g_lua.bindClassMemberFunction("setTileDescription", &ProtocolGame::setTileDescription); + g_lua.bindClassMemberFunction("getOutfit", &ProtocolGame::getOutfit); + g_lua.bindClassMemberFunction("getThing", &ProtocolGame::getThing); + g_lua.bindClassMemberFunction("getCreature", &ProtocolGame::getCreature); + g_lua.bindClassMemberFunction("getItem", &ProtocolGame::getItem); + g_lua.bindClassMemberFunction("getPosition", &ProtocolGame::getPosition); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return ContainerPtr(new Container); }); @@ -256,7 +269,6 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("getId", &Item::getId); g_lua.bindClassMemberFunction("isStackable", &Item::isStackable); - g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); diff --git a/src/otclient/net/protocolcodes.h b/src/otclient/net/protocolcodes.h index 7c1bac55..afb96fbe 100644 --- a/src/otclient/net/protocolcodes.h +++ b/src/otclient/net/protocolcodes.h @@ -55,15 +55,17 @@ namespace Proto { OsLinux = 1, OsWindows = 2, OsFlash = 3, - OsMac = 4 + OsOtclientLinux = 10, + OsOtclientWindows = 11, + OsOtclientMac = 12, }; #ifdef OSTYPE constexpr int ClientOs = OSTYPE; #elif defined WIN32 - constexpr int ClientOs = OsWindows; + constexpr int ClientOs = OsOtclientWindows; #else - constexpr int ClientOs = OsLinux; + constexpr int ClientOs = OsOtclientLinux; #endif #if PROTOCOL>=860 @@ -107,10 +109,9 @@ namespace Proto { GameServerFirstGameOpcode = 50, // NOTE: add any custom opcodes in this range - // 50 - 97 + // 51 - 99 // otclient ONLY - GameServerExtendedP2POpcode = 98, GameServerExtendedOpcode = 99, // original tibia ONLY @@ -203,10 +204,9 @@ namespace Proto { ClientFirstGameOpcode = 50, // NOTE: add any custom opcodes in this range - // 50 - 97 + // 50 - 98 // otclient ONLY - ClientExtendedP2POpcode = 98, ClientExtendedOpcode = 99, // original tibia ONLY diff --git a/src/otclient/net/protocolgame.cpp b/src/otclient/net/protocolgame.cpp index 5de0cac0..f169f212 100644 --- a/src/otclient/net/protocolgame.cpp +++ b/src/otclient/net/protocolgame.cpp @@ -54,7 +54,7 @@ void ProtocolGame::onConnect() recv(); } -void ProtocolGame::onRecv(InputMessage& inputMessage) +void ProtocolGame::onRecv(const InputMessagePtr& inputMessage) { parseMessage(inputMessage); recv(); diff --git a/src/otclient/net/protocolgame.h b/src/otclient/net/protocolgame.h index 0d361735..eb68594e 100644 --- a/src/otclient/net/protocolgame.h +++ b/src/otclient/net/protocolgame.h @@ -32,11 +32,18 @@ class ProtocolGame : public Protocol { public: void login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName); + void send(const OutputMessagePtr& outputMessage); + void sendExtendedOpcode(uint8 opcode, const std::string& buffer); +protected: void onConnect(); - void onRecv(InputMessage& inputMessage); + void onRecv(const InputMessagePtr& inputMessage); void onError(const boost::system::error_code& error); + friend class Game; + +protected: + void sendLoginPacket(uint challangeTimestamp, uint8 challangeRandom); void sendLogout(); void sendPing(); void sendPingBack(); @@ -105,115 +112,105 @@ public: void sendRequestQuestLine(int questId); void sendNewNewRuleViolation(int reason, int action, const std::string& characterName, const std::string& comment, const std::string& translation); void sendRequestItemInfo(int itemId, int index); - /* - void sendMarketLeave(); - void sendMarketBrowse(); - void sendMarketCreate(); - void sendMarketCancel(); - void sendMarketAccept(); - */ - void sendExtendedOpcode(uint8 opcode, const std::string& buffer); -private: - void sendLoginPacket(uint challangeTimestamp, uint8 challangeRandom); - - // Parse Messages - void parseMessage(InputMessage& msg); - - void parseInitGame(InputMessage& msg); - void parseGMActions(InputMessage& msg); - void parseLoginError(InputMessage& msg); - void parseLoginAdvice(InputMessage& msg); - void parseLoginWait(InputMessage& msg); - void parsePing(InputMessage& msg); - void parsePingBack(InputMessage& msg); - void parseChallange(InputMessage& msg); - void parseDeath(InputMessage& msg); - void parseMapDescription(InputMessage& msg); - void parseMapMoveNorth(InputMessage& msg); - void parseMapMoveEast(InputMessage& msg); - void parseMapMoveSouth(InputMessage& msg); - void parseMapMoveWest(InputMessage& msg); - void parseUpdateTile(InputMessage& msg); - void parseTileAddThing(InputMessage& msg); - void parseTileTransformThing(InputMessage& msg); - void parseTileRemoveThing(InputMessage& msg); - void parseCreatureMove(InputMessage& msg); - void parseOpenContainer(InputMessage& msg); - void parseCloseContainer(InputMessage& msg); - void parseContainerAddItem(InputMessage& msg); - void parseContainerUpdateItem(InputMessage& msg); - void parseContainerRemoveItem(InputMessage& msg); - void parseAddInventoryItem(InputMessage& msg); - void parseRemoveInventoryItem(InputMessage& msg); - void parseOpenNpcTrade(InputMessage& msg); - void parsePlayerGoods(InputMessage& msg); - void parseCloseNpcTrade(InputMessage&); - void parseWorldLight(InputMessage& msg); - void parseMagicEffect(InputMessage& msg); - void parseAnimatedText(InputMessage& msg); - void parseDistanceMissile(InputMessage& msg); - void parseCreatureMark(InputMessage& msg); - void parseTrappers(InputMessage& msg); - void parseCreatureHealth(InputMessage& msg); - void parseCreatureLight(InputMessage& msg); - void parseCreatureOutfit(InputMessage& msg); - void parseCreatureSpeed(InputMessage& msg); - void parseCreatureSkulls(InputMessage& msg); - void parseCreatureShields(InputMessage& msg); - void parseCreatureUnpass(InputMessage& msg); - void parseEditText(InputMessage& msg); - void parseEditList(InputMessage& msg); - void parsePlayerInfo(InputMessage& msg); - void parsePlayerStats(InputMessage& msg); - void parsePlayerSkills(InputMessage& msg); - void parsePlayerState(InputMessage& msg); - void parsePlayerCancelAttack(InputMessage& msg); - void parseSpellDelay(InputMessage& msg); - void parseSpellGroupDelay(InputMessage& msg); - void parseMultiUseDelay(InputMessage& msg); - void parseCreatureSpeak(InputMessage& msg); - void parseChannelList(InputMessage& msg); - void parseOpenChannel(InputMessage& msg); - void parseOpenPrivateChannel(InputMessage& msg); - void parseOpenOwnPrivateChannel(InputMessage& msg); - void parseCloseChannel(InputMessage& msg); - void parseRuleViolationChannel(InputMessage& msg); - void parseRuleViolationRemove(InputMessage& msg); - void parseRuleViolationCancel(InputMessage& msg); - void parseRuleViolationLock(InputMessage& msg); - void parseOwnTrade(InputMessage& msg); - void parseCounterTrade(InputMessage& msg); - void parseCloseTrade(InputMessage&); - void parseTextMessage(InputMessage& msg); - void parseCancelWalk(InputMessage& msg); - void parseWalkWait(InputMessage& msg); - void parseFloorChangeUp(InputMessage& msg); - void parseFloorChangeDown(InputMessage& msg); - void parseOpenOutfitWindow(InputMessage& msg); - void parseVipAdd(InputMessage& msg); - void parseVipLogin(InputMessage& msg); - void parseVipLogout(InputMessage& msg); - void parseTutorialHint(InputMessage& msg); - void parseAutomapFlag(InputMessage& msg); - void parseQuestLog(InputMessage& msg); - void parseQuestLine(InputMessage& msg); - void parseChannelEvent(InputMessage& msg); - void parseItemInfo(InputMessage& msg); - void parsePlayerInventory(InputMessage& msg); - void parseExtendedOpcode(InputMessage& msg); +public: + void addPosition(const OutputMessagePtr& msg, const Position& position); - void setMapDescription(InputMessage& msg, int x, int y, int z, int width, int height); - void setFloorDescription(InputMessage& msg, int x, int y, int z, int width, int height, int offset, int* skipTiles); - void setTileDescription(InputMessage& msg, Position position); +private: + void parseMessage(const InputMessagePtr& msg); + void parseInitGame(const InputMessagePtr& msg); + void parseGMActions(const InputMessagePtr& msg); + void parseLoginError(const InputMessagePtr& msg); + void parseLoginAdvice(const InputMessagePtr& msg); + void parseLoginWait(const InputMessagePtr& msg); + void parsePing(const InputMessagePtr& msg); + void parsePingBack(const InputMessagePtr& msg); + void parseChallange(const InputMessagePtr& msg); + void parseDeath(const InputMessagePtr& msg); + void parseMapDescription(const InputMessagePtr& msg); + void parseMapMoveNorth(const InputMessagePtr& msg); + void parseMapMoveEast(const InputMessagePtr& msg); + void parseMapMoveSouth(const InputMessagePtr& msg); + void parseMapMoveWest(const InputMessagePtr& msg); + void parseUpdateTile(const InputMessagePtr& msg); + void parseTileAddThing(const InputMessagePtr& msg); + void parseTileTransformThing(const InputMessagePtr& msg); + void parseTileRemoveThing(const InputMessagePtr& msg); + void parseCreatureMove(const InputMessagePtr& msg); + void parseOpenContainer(const InputMessagePtr& msg); + void parseCloseContainer(const InputMessagePtr& msg); + void parseContainerAddItem(const InputMessagePtr& msg); + void parseContainerUpdateItem(const InputMessagePtr& msg); + void parseContainerRemoveItem(const InputMessagePtr& msg); + void parseAddInventoryItem(const InputMessagePtr& msg); + void parseRemoveInventoryItem(const InputMessagePtr& msg); + void parseOpenNpcTrade(const InputMessagePtr& msg); + void parsePlayerGoods(const InputMessagePtr& msg); + void parseCloseNpcTrade(const InputMessagePtr&); + void parseWorldLight(const InputMessagePtr& msg); + void parseMagicEffect(const InputMessagePtr& msg); + void parseAnimatedText(const InputMessagePtr& msg); + void parseDistanceMissile(const InputMessagePtr& msg); + void parseCreatureMark(const InputMessagePtr& msg); + void parseTrappers(const InputMessagePtr& msg); + void parseCreatureHealth(const InputMessagePtr& msg); + void parseCreatureLight(const InputMessagePtr& msg); + void parseCreatureOutfit(const InputMessagePtr& msg); + void parseCreatureSpeed(const InputMessagePtr& msg); + void parseCreatureSkulls(const InputMessagePtr& msg); + void parseCreatureShields(const InputMessagePtr& msg); + void parseCreatureUnpass(const InputMessagePtr& msg); + void parseEditText(const InputMessagePtr& msg); + void parseEditList(const InputMessagePtr& msg); + void parsePlayerInfo(const InputMessagePtr& msg); + void parsePlayerStats(const InputMessagePtr& msg); + void parsePlayerSkills(const InputMessagePtr& msg); + void parsePlayerState(const InputMessagePtr& msg); + void parsePlayerCancelAttack(const InputMessagePtr& msg); + void parseSpellDelay(const InputMessagePtr& msg); + void parseSpellGroupDelay(const InputMessagePtr& msg); + void parseMultiUseDelay(const InputMessagePtr& msg); + void parseCreatureSpeak(const InputMessagePtr& msg); + void parseChannelList(const InputMessagePtr& msg); + void parseOpenChannel(const InputMessagePtr& msg); + void parseOpenPrivateChannel(const InputMessagePtr& msg); + void parseOpenOwnPrivateChannel(const InputMessagePtr& msg); + void parseCloseChannel(const InputMessagePtr& msg); + void parseRuleViolationChannel(const InputMessagePtr& msg); + void parseRuleViolationRemove(const InputMessagePtr& msg); + void parseRuleViolationCancel(const InputMessagePtr& msg); + void parseRuleViolationLock(const InputMessagePtr& msg); + void parseOwnTrade(const InputMessagePtr& msg); + void parseCounterTrade(const InputMessagePtr& msg); + void parseCloseTrade(const InputMessagePtr&); + void parseTextMessage(const InputMessagePtr& msg); + void parseCancelWalk(const InputMessagePtr& msg); + void parseWalkWait(const InputMessagePtr& msg); + void parseFloorChangeUp(const InputMessagePtr& msg); + void parseFloorChangeDown(const InputMessagePtr& msg); + void parseOpenOutfitWindow(const InputMessagePtr& msg); + void parseVipAdd(const InputMessagePtr& msg); + void parseVipLogin(const InputMessagePtr& msg); + void parseVipLogout(const InputMessagePtr& msg); + void parseTutorialHint(const InputMessagePtr& msg); + void parseAutomapFlag(const InputMessagePtr& msg); + void parseQuestLog(const InputMessagePtr& msg); + void parseQuestLine(const InputMessagePtr& msg); + void parseChannelEvent(const InputMessagePtr& msg); + void parseItemInfo(const InputMessagePtr& msg); + void parsePlayerInventory(const InputMessagePtr& msg); + void parseExtendedOpcode(const InputMessagePtr& msg); - Outfit internalGetOutfit(InputMessage& msg); - CreaturePtr internalGetCreature(InputMessage& msg, int type = 0); - ThingPtr internalGetThing(InputMessage& msg); - ItemPtr internalGetItem(InputMessage& msg, int id = 0); +public: + void setMapDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height); + int setFloorDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height, int offset, int skip); + void setTileDescription(const InputMessagePtr& msg, Position position); - void addPosition(OutputMessage& msg, const Position& position); - Position parsePosition(InputMessage& msg); + Outfit getOutfit(const InputMessagePtr& msg); + ThingPtr getThing(const InputMessagePtr& msg); + CreaturePtr getCreature(const InputMessagePtr& msg, int type = 0); + ItemPtr getItem(const InputMessagePtr& msg, int id = 0); + Position getPosition(const InputMessagePtr& msg); private: Boolean m_gameInitialized; diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 37bafd5b..33ff79a0 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -33,14 +33,18 @@ #include #include -void ProtocolGame::parseMessage(InputMessage& msg) +void ProtocolGame::parseMessage(const InputMessagePtr& msg) { int opcode = 0; int prevOpcode = 0; try { - while(!msg.eof()) { - opcode = msg.getU8(); + while(!msg->eof()) { + opcode = msg->getU8(); + + // try to parse in lua first + if(callLuaField("onOpcode", opcode, msg)) + continue; if(!m_gameInitialized && opcode >= Proto::GameServerFirstGameOpcode) logWarning("received a game opcode from the server, but the game is not initialized yet, this is a server side bug"); @@ -309,86 +313,86 @@ void ProtocolGame::parseMessage(InputMessage& msg) prevOpcode = opcode; } } catch(Exception& e) { - logError("Network exception (", msg.getUnreadSize(), " bytes unread, last opcode is ", opcode, ", prev opcode is ", prevOpcode, "): ", e.what()); + logError("Network exception (", msg->getUnreadSize(), " bytes unread, last opcode is ", opcode, ", prev opcode is ", prevOpcode, "): ", e.what()); } } -void ProtocolGame::parseInitGame(InputMessage& msg) +void ProtocolGame::parseInitGame(const InputMessagePtr& msg) { m_gameInitialized = true; - uint playerId = msg.getU32(); - int serverBeat = msg.getU16(); - bool canReportBugs = msg.getU8(); + uint playerId = msg->getU32(); + int serverBeat = msg->getU16(); + bool canReportBugs = msg->getU8(); m_localPlayer->setId(playerId); g_game.processGameStart(m_localPlayer, serverBeat, canReportBugs); } -void ProtocolGame::parseGMActions(InputMessage& msg) +void ProtocolGame::parseGMActions(const InputMessagePtr& msg) { std::vector actions; for(int i = 0; i < Proto::NumViolationReasons; ++i) - actions.push_back(msg.getU8()); + actions.push_back(msg->getU8()); g_game.processGMActions(actions); } -void ProtocolGame::parseLoginError(InputMessage& msg) +void ProtocolGame::parseLoginError(const InputMessagePtr& msg) { - std::string error = msg.getString(); + std::string error = msg->getString(); g_game.processLoginError(error); } -void ProtocolGame::parseLoginAdvice(InputMessage& msg) +void ProtocolGame::parseLoginAdvice(const InputMessagePtr& msg) { - std::string message = msg.getString(); + std::string message = msg->getString(); g_game.processLoginAdvice(message); } -void ProtocolGame::parseLoginWait(InputMessage& msg) +void ProtocolGame::parseLoginWait(const InputMessagePtr& msg) { - std::string message = msg.getString(); - int time = msg.getU8(); + std::string message = msg->getString(); + int time = msg->getU8(); g_game.processLoginWait(message, time); } -void ProtocolGame::parsePing(InputMessage& msg) +void ProtocolGame::parsePing(const InputMessagePtr& msg) { g_game.processPing(); sendPingBack(); } -void ProtocolGame::parsePingBack(InputMessage& msg) +void ProtocolGame::parsePingBack(const InputMessagePtr& msg) { // nothing to do } -void ProtocolGame::parseChallange(InputMessage& msg) +void ProtocolGame::parseChallange(const InputMessagePtr& msg) { - uint32 timestamp = msg.getU32(); - uint8 random = msg.getU8(); + uint timestamp = msg->getU32(); + uint8 random = msg->getU8(); sendLoginPacket(timestamp, random); } -void ProtocolGame::parseDeath(InputMessage& msg) +void ProtocolGame::parseDeath(const InputMessagePtr& msg) { int penality = 100; #if PROTOCOL>=862 - penality = msg.getU8(); + penality = msg->getU8(); #endif g_game.processDeath(penality); } -void ProtocolGame::parseMapDescription(InputMessage& msg) +void ProtocolGame::parseMapDescription(const InputMessagePtr& msg) { - Position pos = parsePosition(msg); + Position pos = getPosition(msg); g_map.setCentralPosition(pos); setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES); } -void ProtocolGame::parseMapMoveNorth(InputMessage& msg) +void ProtocolGame::parseMapMoveNorth(const InputMessagePtr& msg) { Position pos = g_map.getCentralPosition(); pos.y--; @@ -397,7 +401,7 @@ void ProtocolGame::parseMapMoveNorth(InputMessage& msg) g_map.setCentralPosition(pos); } -void ProtocolGame::parseMapMoveEast(InputMessage& msg) +void ProtocolGame::parseMapMoveEast(const InputMessagePtr& msg) { Position pos = g_map.getCentralPosition(); pos.x++; @@ -406,7 +410,7 @@ void ProtocolGame::parseMapMoveEast(InputMessage& msg) g_map.setCentralPosition(pos); } -void ProtocolGame::parseMapMoveSouth(InputMessage& msg) +void ProtocolGame::parseMapMoveSouth(const InputMessagePtr& msg) { Position pos = g_map.getCentralPosition(); pos.y++; @@ -415,7 +419,7 @@ void ProtocolGame::parseMapMoveSouth(InputMessage& msg) g_map.setCentralPosition(pos); } -void ProtocolGame::parseMapMoveWest(InputMessage& msg) +void ProtocolGame::parseMapMoveWest(const InputMessagePtr& msg) { Position pos = g_map.getCentralPosition(); pos.x--; @@ -424,38 +428,37 @@ void ProtocolGame::parseMapMoveWest(InputMessage& msg) g_map.setCentralPosition(pos); } -void ProtocolGame::parseUpdateTile(InputMessage& msg) +void ProtocolGame::parseUpdateTile(const InputMessagePtr& msg) { - Position tilePos = parsePosition(msg); - g_map.cleanTile(tilePos); - int thingId = msg.getU16(true); + Position tilePos = getPosition(msg); + int thingId = msg->getU16(true); if(thingId == 0xFF01) { - msg.getU16(); + msg->getU16(); } else { setTileDescription(msg, tilePos); - msg.getU16(); + msg->getU16(); } } -void ProtocolGame::parseTileAddThing(InputMessage& msg) +void ProtocolGame::parseTileAddThing(const InputMessagePtr& msg) { - Position pos = parsePosition(msg); + Position pos = getPosition(msg); int stackPos = -1; #if PROTOCOL>=854 - stackPos = msg.getU8(); + stackPos = msg->getU8(); #endif - ThingPtr thing = internalGetThing(msg); + ThingPtr thing = getThing(msg); g_map.addThing(thing, pos, stackPos); } -void ProtocolGame::parseTileTransformThing(InputMessage& msg) +void ProtocolGame::parseTileTransformThing(const InputMessagePtr& msg) { - Position pos = parsePosition(msg); - int stackPos = msg.getU8(); + Position pos = getPosition(msg); + int stackPos = msg->getU8(); - ThingPtr thing = internalGetThing(msg); + ThingPtr thing = getThing(msg); if(thing) { if(!g_map.removeThingByPos(pos, stackPos)) logTraceError("could not remove thing"); @@ -463,20 +466,20 @@ void ProtocolGame::parseTileTransformThing(InputMessage& msg) } } -void ProtocolGame::parseTileRemoveThing(InputMessage& msg) +void ProtocolGame::parseTileRemoveThing(const InputMessagePtr& msg) { - Position pos = parsePosition(msg); - int stackPos = msg.getU8(); + Position pos = getPosition(msg); + int stackPos = msg->getU8(); if(!g_map.removeThingByPos(pos, stackPos)) logTraceError("could not remove thing"); } -void ProtocolGame::parseCreatureMove(InputMessage& msg) +void ProtocolGame::parseCreatureMove(const InputMessagePtr& msg) { - Position oldPos = parsePosition(msg); - int oldStackpos = msg.getU8(); - Position newPos = parsePosition(msg); + Position oldPos = getPosition(msg); + int oldStackpos = msg->getU8(); + Position newPos = getPosition(msg); ThingPtr thing = g_map.getThing(oldPos, oldStackpos); if(!thing) { @@ -496,99 +499,99 @@ void ProtocolGame::parseCreatureMove(InputMessage& msg) g_map.addThing(thing, newPos); } -void ProtocolGame::parseOpenContainer(InputMessage& msg) +void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg) { - int containerId = msg.getU8(); - ItemPtr containerItem = internalGetItem(msg); - std::string name = msg.getString(); - int capacity = msg.getU8(); - bool hasParent = (msg.getU8() != 0); - int itemCount = msg.getU8(); + int containerId = msg->getU8(); + ItemPtr containerItem = getItem(msg); + std::string name = msg->getString(); + int capacity = msg->getU8(); + bool hasParent = (msg->getU8() != 0); + int itemCount = msg->getU8(); std::vector items(itemCount); for(int i = 0; i < itemCount; i++) - items[i] = internalGetItem(msg); + items[i] = getItem(msg); g_game.processOpenContainer(containerId, containerItem, name, capacity, hasParent, items); } -void ProtocolGame::parseCloseContainer(InputMessage& msg) +void ProtocolGame::parseCloseContainer(const InputMessagePtr& msg) { - int containerId = msg.getU8(); + int containerId = msg->getU8(); g_game.processCloseContainer(containerId); } -void ProtocolGame::parseContainerAddItem(InputMessage& msg) +void ProtocolGame::parseContainerAddItem(const InputMessagePtr& msg) { - int containerId = msg.getU8(); - ItemPtr item = internalGetItem(msg); + int containerId = msg->getU8(); + ItemPtr item = getItem(msg); g_game.processContainerAddItem(containerId, item); } -void ProtocolGame::parseContainerUpdateItem(InputMessage& msg) +void ProtocolGame::parseContainerUpdateItem(const InputMessagePtr& msg) { - int containerId = msg.getU8(); - int slot = msg.getU8(); - ItemPtr item = internalGetItem(msg); + int containerId = msg->getU8(); + int slot = msg->getU8(); + ItemPtr item = getItem(msg); g_game.processContainerUpdateItem(containerId, slot, item); } -void ProtocolGame::parseContainerRemoveItem(InputMessage& msg) +void ProtocolGame::parseContainerRemoveItem(const InputMessagePtr& msg) { - int containerId = msg.getU8(); - int slot = msg.getU8(); + int containerId = msg->getU8(); + int slot = msg->getU8(); g_game.processContainerRemoveItem(containerId, slot); } -void ProtocolGame::parseAddInventoryItem(InputMessage& msg) +void ProtocolGame::parseAddInventoryItem(const InputMessagePtr& msg) { - int slot = msg.getU8(); - ItemPtr item = internalGetItem(msg); + int slot = msg->getU8(); + ItemPtr item = getItem(msg); g_game.processInventoryChange(slot, item); } -void ProtocolGame::parseRemoveInventoryItem(InputMessage& msg) +void ProtocolGame::parseRemoveInventoryItem(const InputMessagePtr& msg) { - int slot = msg.getU8(); + int slot = msg->getU8(); g_game.processInventoryChange(slot, ItemPtr()); } -void ProtocolGame::parseOpenNpcTrade(InputMessage& msg) +void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg) { std::vector> items; std::string npcName; #if PROTOCOL>=910 - npcName = msg.getString(); + npcName = msg->getString(); #endif - int listCount = msg.getU8(); + int listCount = msg->getU8(); for(int i = 0; i < listCount; ++i) { - uint16 itemId = msg.getU16(); - uint8 count = msg.getU8(); + uint16 itemId = msg->getU16(); + uint8 count = msg->getU8(); ItemPtr item = Item::create(itemId); item->setCountOrSubType(count); - std::string name = msg.getString(); - int weight = msg.getU32(); - int buyPrice = msg.getU32(); - int sellPrice = msg.getU32(); + std::string name = msg->getString(); + int weight = msg->getU32(); + int buyPrice = msg->getU32(); + int sellPrice = msg->getU32(); items.push_back(std::make_tuple(item, name, weight, buyPrice, sellPrice)); } g_game.processOpenNpcTrade(items); } -void ProtocolGame::parsePlayerGoods(InputMessage& msg) +void ProtocolGame::parsePlayerGoods(const InputMessagePtr& msg) { std::vector> goods; - int money = msg.getU32(); - int size = msg.getU8(); + int money = msg->getU32(); + int size = msg->getU8(); for(int i = 0; i < size; i++) { - int itemId = msg.getU16(); - int count = msg.getU8(); + int itemId = msg->getU16(); + int count = msg->getU8(); goods.push_back(std::make_tuple(Item::create(itemId), count)); } @@ -596,64 +599,64 @@ void ProtocolGame::parsePlayerGoods(InputMessage& msg) g_game.processPlayerGoods(money, goods); } -void ProtocolGame::parseCloseNpcTrade(InputMessage&) +void ProtocolGame::parseCloseNpcTrade(const InputMessagePtr&) { g_game.processCloseNpcTrade(); } -void ProtocolGame::parseOwnTrade(InputMessage& msg) +void ProtocolGame::parseOwnTrade(const InputMessagePtr& msg) { - std::string name = msg.getString(); - int count = msg.getU8(); + std::string name = msg->getString(); + int count = msg->getU8(); std::vector items(count); for(int i = 0; i < count; i++) - items[i] = internalGetItem(msg); + items[i] = getItem(msg); g_game.processOwnTrade(name, items); } -void ProtocolGame::parseCounterTrade(InputMessage& msg) +void ProtocolGame::parseCounterTrade(const InputMessagePtr& msg) { - std::string name = msg.getString(); - int count = msg.getU8(); + std::string name = msg->getString(); + int count = msg->getU8(); std::vector items(count); for(int i = 0; i < count; i++) - items[i] = internalGetItem(msg); + items[i] = getItem(msg); g_game.processCounterTrade(name, items); } -void ProtocolGame::parseCloseTrade(InputMessage&) +void ProtocolGame::parseCloseTrade(const InputMessagePtr&) { g_game.processCloseTrade(); } -void ProtocolGame::parseWorldLight(InputMessage& msg) +void ProtocolGame::parseWorldLight(const InputMessagePtr& msg) { Light light; - light.intensity = msg.getU8(); - light.color = msg.getU8(); + light.intensity = msg->getU8(); + light.color = msg->getU8(); g_map.setLight(light); } -void ProtocolGame::parseMagicEffect(InputMessage& msg) +void ProtocolGame::parseMagicEffect(const InputMessagePtr& msg) { - Position pos = parsePosition(msg); - int effectId = msg.getU8(); + Position pos = getPosition(msg); + int effectId = msg->getU8(); EffectPtr effect = EffectPtr(new Effect()); effect->setId(effectId); g_map.addThing(effect, pos); } -void ProtocolGame::parseAnimatedText(InputMessage& msg) +void ProtocolGame::parseAnimatedText(const InputMessagePtr& msg) { - Position position = parsePosition(msg); - int color = msg.getU8(); - std::string text = msg.getString(); + Position position = getPosition(msg); + int color = msg->getU8(); + std::string text = msg->getString(); AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); animatedText->setColor(color); @@ -661,11 +664,11 @@ void ProtocolGame::parseAnimatedText(InputMessage& msg) g_map.addThing(animatedText, position); } -void ProtocolGame::parseDistanceMissile(InputMessage& msg) +void ProtocolGame::parseDistanceMissile(const InputMessagePtr& msg) { - Position fromPos = parsePosition(msg); - Position toPos = parsePosition(msg); - int shotId = msg.getU8(); + Position fromPos = getPosition(msg); + Position toPos = getPosition(msg); + int shotId = msg->getU8(); MissilePtr missile = MissilePtr(new Missile()); missile->setId(shotId); @@ -673,10 +676,10 @@ void ProtocolGame::parseDistanceMissile(InputMessage& msg) g_map.addThing(missile, fromPos); } -void ProtocolGame::parseCreatureMark(InputMessage& msg) +void ProtocolGame::parseCreatureMark(const InputMessagePtr& msg) { - uint id = msg.getU32(); - int color = msg.getU8(); + uint id = msg->getU32(); + int color = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -685,15 +688,15 @@ void ProtocolGame::parseCreatureMark(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseTrappers(InputMessage& msg) +void ProtocolGame::parseTrappers(const InputMessagePtr& msg) { - int numTrappers = msg.getU8(); + int numTrappers = msg->getU8(); if(numTrappers > 8) logTraceError("too many trappers"); for(int i=0;igetU32(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) { //TODO: set creature as trapper @@ -702,10 +705,10 @@ void ProtocolGame::parseTrappers(InputMessage& msg) } } -void ProtocolGame::parseCreatureHealth(InputMessage& msg) +void ProtocolGame::parseCreatureHealth(const InputMessagePtr& msg) { - uint id = msg.getU32(); - int healthPercent = msg.getU8(); + uint id = msg->getU32(); + int healthPercent = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -714,13 +717,13 @@ void ProtocolGame::parseCreatureHealth(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseCreatureLight(InputMessage& msg) +void ProtocolGame::parseCreatureLight(const InputMessagePtr& msg) { - uint id = msg.getU32(); + uint id = msg->getU32(); Light light; - light.intensity = msg.getU8(); - light.color = msg.getU8(); + light.intensity = msg->getU8(); + light.color = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -729,10 +732,10 @@ void ProtocolGame::parseCreatureLight(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseCreatureOutfit(InputMessage& msg) +void ProtocolGame::parseCreatureOutfit(const InputMessagePtr& msg) { - uint id = msg.getU32(); - Outfit outfit = internalGetOutfit(msg); + uint id = msg->getU32(); + Outfit outfit = getOutfit(msg); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -741,10 +744,10 @@ void ProtocolGame::parseCreatureOutfit(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseCreatureSpeed(InputMessage& msg) +void ProtocolGame::parseCreatureSpeed(const InputMessagePtr& msg) { - uint id = msg.getU32(); - int speed = msg.getU16(); + uint id = msg->getU32(); + int speed = msg->getU16(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -753,10 +756,10 @@ void ProtocolGame::parseCreatureSpeed(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseCreatureSkulls(InputMessage& msg) +void ProtocolGame::parseCreatureSkulls(const InputMessagePtr& msg) { - uint id = msg.getU32(); - int skull = msg.getU8(); + uint id = msg->getU32(); + int skull = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -765,10 +768,10 @@ void ProtocolGame::parseCreatureSkulls(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseCreatureShields(InputMessage& msg) +void ProtocolGame::parseCreatureShields(const InputMessagePtr& msg) { - uint id = msg.getU32(); - int shield = msg.getU8(); + uint id = msg->getU32(); + int shield = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -777,10 +780,10 @@ void ProtocolGame::parseCreatureShields(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseCreatureUnpass(InputMessage& msg) +void ProtocolGame::parseCreatureUnpass(const InputMessagePtr& msg) { - uint id = msg.getU32(); - bool unpass = msg.getU8(); + uint id = msg->getU32(); + bool unpass = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -789,65 +792,65 @@ void ProtocolGame::parseCreatureUnpass(InputMessage& msg) logTraceError("could not get creature"); } -void ProtocolGame::parseEditText(InputMessage& msg) +void ProtocolGame::parseEditText(const InputMessagePtr& msg) { - uint id = msg.getU32(); - int itemId = msg.getU16(); - int maxLength = msg.getU16(); - std::string text = msg.getString(); - std::string writter = msg.getString(); - std::string date = msg.getString(); + uint id = msg->getU32(); + int itemId = msg->getU16(); + int maxLength = msg->getU16(); + std::string text = msg->getString(); + std::string writter = msg->getString(); + std::string date = msg->getString(); g_game.processEditText(id, itemId, maxLength, text, writter, date); } -void ProtocolGame::parseEditList(InputMessage& msg) +void ProtocolGame::parseEditList(const InputMessagePtr& msg) { - int doorId = msg.getU8(); - uint id = msg.getU32(); - const std::string& text = msg.getString(); + int doorId = msg->getU8(); + uint id = msg->getU32(); + const std::string& text = msg->getString(); g_game.processEditList(id, doorId, text); } -void ProtocolGame::parsePlayerInfo(InputMessage& msg) +void ProtocolGame::parsePlayerInfo(const InputMessagePtr& msg) { - msg.getU8(); // is premium? - msg.getU8(); // profession - int numSpells = msg.getU16(); + msg->getU8(); // is premium? + msg->getU8(); // profession + int numSpells = msg->getU16(); for(int i=0;igetU16(); // spell id } } -void ProtocolGame::parsePlayerStats(InputMessage& msg) +void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) { - double health = msg.getU16(); - double maxHealth = msg.getU16(); + double health = msg->getU16(); + double maxHealth = msg->getU16(); #if PROTOCOL>=854 - double freeCapacity = msg.getU32() / 100.0; + double freeCapacity = msg->getU32() / 100.0; #else - double freeCapacity = msg.getU16() / 100.0; + double freeCapacity = msg->getU16() / 100.0; #endif #if PROTOCOL>=910 - msg.getU32(); // total capacity + msg->getU32(); // total capacity #endif #if PROTOCOL>=870 - double experience = msg.getU64(); + double experience = msg->getU64(); #else - double experience = msg.getU32(); + double experience = msg->getU32(); #endif - double level = msg.getU16(); - double levelPercent = msg.getU8(); - double mana = msg.getU16(); - double maxMana = msg.getU16(); - double magicLevel = msg.getU8(); + double level = msg->getU16(); + double levelPercent = msg->getU8(); + double mana = msg->getU16(); + double maxMana = msg->getU16(); + double magicLevel = msg->getU8(); #if PROTOCOL>=910 - msg.getU8(); // base magic level + msg->getU8(); // base magic level #endif - double magicLevelPercent = msg.getU8(); - double soul = msg.getU8(); - double stamina = msg.getU16(); + double magicLevelPercent = msg->getU8(); + double soul = msg->getU8(); + double stamina = msg->getU16(); m_localPlayer->setHealth(health, maxHealth); m_localPlayer->setFreeCapacity(freeCapacity); @@ -859,68 +862,68 @@ void ProtocolGame::parsePlayerStats(InputMessage& msg) m_localPlayer->setSoul(soul); #if PROTOCOL>=910 - int speed = msg.getU16(); - msg.getU16(); // regeneration time + int speed = msg->getU16(); + msg->getU16(); // regeneration time m_localPlayer->setSpeed(speed); #endif } -void ProtocolGame::parsePlayerSkills(InputMessage& msg) +void ProtocolGame::parsePlayerSkills(const InputMessagePtr& msg) { for(int skill = 0; skill < Otc::LastSkill; skill++) { - int level = msg.getU8(); + int level = msg->getU8(); #if PROTOCOL>=910 - msg.getU8(); // base + msg->getU8(); // base #endif - int levelPercent = msg.getU8(); + int levelPercent = msg->getU8(); m_localPlayer->setSkill((Otc::Skill)skill, level, levelPercent); } } -void ProtocolGame::parsePlayerState(InputMessage& msg) +void ProtocolGame::parsePlayerState(const InputMessagePtr& msg) { - int states = msg.getU16(); + int states = msg->getU16(); m_localPlayer->setStates(states); } -void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg) +void ProtocolGame::parsePlayerCancelAttack(const InputMessagePtr& msg) { #if PROTOCOL>=860 - msg.getU32(); // unknown + msg->getU32(); // unknown #endif g_game.processAttackCancel(); } -void ProtocolGame::parseSpellDelay(InputMessage& msg) +void ProtocolGame::parseSpellDelay(const InputMessagePtr& msg) { - msg.getU16(); // spell id - msg.getU16(); // cooldown - msg.getU8(); // unknown + msg->getU16(); // spell id + msg->getU16(); // cooldown + msg->getU8(); // unknown } -void ProtocolGame::parseSpellGroupDelay(InputMessage& msg) +void ProtocolGame::parseSpellGroupDelay(const InputMessagePtr& msg) { - msg.getU16(); // spell id - msg.getU16(); // cooldown - msg.getU8(); // unknown + msg->getU16(); // spell id + msg->getU16(); // cooldown + msg->getU8(); // unknown } -void ProtocolGame::parseMultiUseDelay(InputMessage& msg) +void ProtocolGame::parseMultiUseDelay(const InputMessagePtr& msg) { //TODO } -void ProtocolGame::parseCreatureSpeak(InputMessage& msg) +void ProtocolGame::parseCreatureSpeak(const InputMessagePtr& msg) { - msg.getU32(); // channel statement guid + msg->getU32(); // channel statement guid - std::string name = msg.getString(); - int level = msg.getU16(); - int speakType = msg.getU8(); + std::string name = msg->getString(); + int level = msg->getU16(); + int speakType = msg->getU8(); int channelId = 0; Position creaturePos; @@ -931,14 +934,14 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg) case Proto::ServerSpeakMonsterSay: case Proto::ServerSpeakMonsterYell: case Proto::ServerSpeakPrivateNpcToPlayer: - creaturePos = parsePosition(msg); + creaturePos = getPosition(msg); break; case Proto::ServerSpeakChannelYellow: case Proto::ServerSpeakChannelWhite: case Proto::ServerSpeakChannelRed: case Proto::ServerSpeakChannelRed2: case Proto::ServerSpeakChannelOrange: - channelId = msg.getU16(); + channelId = msg->getU16(); break; case Proto::ServerSpeakPrivateFrom: case Proto::ServerSpeakPrivatePlayerToNpc: @@ -946,7 +949,7 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg) case Proto::ServerSpeakPrivateRedFrom: break; case Proto::ServerSpeakRVRChannel: - msg.getU32(); + msg->getU32(); break; //case Proto::ServerSpeakChannelManagement: //case Proto::ServerSpeakSpell: @@ -955,115 +958,115 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg) break; } - std::string message = msg.getString(); + std::string message = msg->getString(); Otc::SpeakType type = Proto::translateSpeakTypeFromServer(speakType); g_game.processCreatureSpeak(name, level, type, message, channelId, creaturePos); } -void ProtocolGame::parseChannelList(InputMessage& msg) +void ProtocolGame::parseChannelList(const InputMessagePtr& msg) { - int count = msg.getU8(); + int count = msg->getU8(); std::vector> channelList; for(int i = 0; i < count; i++) { - int id = msg.getU16(); - std::string name = msg.getString(); + int id = msg->getU16(); + std::string name = msg->getString(); channelList.push_back(std::make_tuple(id, name)); } g_game.processChannelList(channelList); } -void ProtocolGame::parseOpenChannel(InputMessage& msg) +void ProtocolGame::parseOpenChannel(const InputMessagePtr& msg) { - int channelId = msg.getU16(); - std::string name = msg.getString(); + int channelId = msg->getU16(); + std::string name = msg->getString(); #if PROTOCOL>=944 - int joinedPlayers = msg.getU16(); + int joinedPlayers = msg->getU16(); for(int i=0;igetString(); // player name + int invitedPlayers = msg->getU16(); for(int i=0;igetString(); // player name #endif g_game.processOpenChannel(channelId, name); } -void ProtocolGame::parseOpenPrivateChannel(InputMessage& msg) +void ProtocolGame::parseOpenPrivateChannel(const InputMessagePtr& msg) { - std::string name = msg.getString(); + std::string name = msg->getString(); g_game.processOpenPrivateChannel(name); } -void ProtocolGame::parseOpenOwnPrivateChannel(InputMessage& msg) +void ProtocolGame::parseOpenOwnPrivateChannel(const InputMessagePtr& msg) { - int channelId = msg.getU16(); - std::string name = msg.getString(); + int channelId = msg->getU16(); + std::string name = msg->getString(); g_game.processOpenOwnPrivateChannel(channelId, name); } -void ProtocolGame::parseCloseChannel(InputMessage& msg) +void ProtocolGame::parseCloseChannel(const InputMessagePtr& msg) { - int channelId = msg.getU16(); + int channelId = msg->getU16(); g_game.processCloseChannel(channelId); } -void ProtocolGame::parseRuleViolationChannel(InputMessage& msg) +void ProtocolGame::parseRuleViolationChannel(const InputMessagePtr& msg) { - int channelId = msg.getU16(); + int channelId = msg->getU16(); g_game.processRuleViolationChannel(channelId); } -void ProtocolGame::parseRuleViolationRemove(InputMessage& msg) +void ProtocolGame::parseRuleViolationRemove(const InputMessagePtr& msg) { - std::string name = msg.getString(); + std::string name = msg->getString(); g_game.processRuleViolationRemove(name); } -void ProtocolGame::parseRuleViolationCancel(InputMessage& msg) +void ProtocolGame::parseRuleViolationCancel(const InputMessagePtr& msg) { - std::string name = msg.getString(); + std::string name = msg->getString(); g_game.processRuleViolationCancel(name); } -void ProtocolGame::parseRuleViolationLock(InputMessage& msg) +void ProtocolGame::parseRuleViolationLock(const InputMessagePtr& msg) { g_game.processRuleViolationLock(); } -void ProtocolGame::parseTextMessage(InputMessage& msg) +void ProtocolGame::parseTextMessage(const InputMessagePtr& msg) { - int type = msg.getU8(); + int type = msg->getU8(); std::string typeDesc = Proto::translateTextMessageType(type); - std::string message = msg.getString(); + std::string message = msg->getString(); g_game.processTextMessage(typeDesc, message); } -void ProtocolGame::parseCancelWalk(InputMessage& msg) +void ProtocolGame::parseCancelWalk(const InputMessagePtr& msg) { - Otc::Direction direction = (Otc::Direction)msg.getU8(); + Otc::Direction direction = (Otc::Direction)msg->getU8(); g_game.processWalkCancel(direction); } -void ProtocolGame::parseWalkWait(InputMessage& msg) +void ProtocolGame::parseWalkWait(const InputMessagePtr& msg) { //TODO: implement walk wait time - msg.getU16(); // time + msg->getU16(); // time } -void ProtocolGame::parseFloorChangeUp(InputMessage& msg) +void ProtocolGame::parseFloorChangeUp(const InputMessagePtr& msg) { Position pos = g_map.getCentralPosition(); pos.z--; @@ -1071,16 +1074,16 @@ void ProtocolGame::parseFloorChangeUp(InputMessage& msg) int skip = 0; if(pos.z == Otc::SEA_FLOOR) for(int i = Otc::SEA_FLOOR - Otc::AWARE_UNDEGROUND_FLOOR_RANGE; i >= 0; i--) - setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, i, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, 8 - i, &skip); + skip = setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, i, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, 8 - i, skip); else if(pos.z > Otc::SEA_FLOOR) - setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, 3, &skip); + skip = setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, 3, skip); pos.x++; pos.y++; g_map.setCentralPosition(pos); } -void ProtocolGame::parseFloorChangeDown(InputMessage& msg) +void ProtocolGame::parseFloorChangeDown(const InputMessagePtr& msg) { Position pos = g_map.getCentralPosition(); pos.z++; @@ -1089,132 +1092,132 @@ void ProtocolGame::parseFloorChangeDown(InputMessage& msg) if(pos.z == Otc::UNDERGROUND_FLOOR) { int j, i; for(i = pos.z, j = -1; i <= pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE; ++i, --j) - setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, i, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, j, &skip); + skip = setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, i, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, j, skip); } else if(pos.z > Otc::UNDERGROUND_FLOOR && pos.z < Otc::MAX_Z-1) - setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, -3, &skip); + skip = setFloorDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES, -3, skip); pos.x--; pos.y--; g_map.setCentralPosition(pos); } -void ProtocolGame::parseOpenOutfitWindow(InputMessage& msg) +void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) { - Outfit currentOutfit = internalGetOutfit(msg); + Outfit currentOutfit = getOutfit(msg); std::vector> outfitList; - int outfitCount = msg.getU8(); + int outfitCount = msg->getU8(); for(int i = 0; i < outfitCount; i++) { - int outfitId = msg.getU16(); - std::string outfitName = msg.getString(); - int outfitAddons = msg.getU8(); + int outfitId = msg->getU16(); + std::string outfitName = msg->getString(); + int outfitAddons = msg->getU8(); outfitList.push_back(std::make_tuple(outfitId, outfitName, outfitAddons)); } #if PROTOCOL>=870 - int mountCount = msg.getU8(); + int mountCount = msg->getU8(); for(int i=0;igetU16(); // mount type + msg->getString(); // mount name } #endif g_game.processOpenOutfitWindow(currentOutfit, outfitList); } -void ProtocolGame::parseVipAdd(InputMessage& msg) +void ProtocolGame::parseVipAdd(const InputMessagePtr& msg) { - uint id = msg.getU32(); - std::string name = msg.getString(); - bool online = msg.getU8() != 0; + uint id = msg->getU32(); + std::string name = msg->getString(); + bool online = msg->getU8() != 0; g_game.processVipAdd(id, name, online); } -void ProtocolGame::parseVipLogin(InputMessage& msg) +void ProtocolGame::parseVipLogin(const InputMessagePtr& msg) { - uint id = msg.getU32(); + uint id = msg->getU32(); g_game.processVipStateChange(id, true); } -void ProtocolGame::parseVipLogout(InputMessage& msg) +void ProtocolGame::parseVipLogout(const InputMessagePtr& msg) { - uint id = msg.getU32(); + uint id = msg->getU32(); g_game.processVipStateChange(id, false); } -void ProtocolGame::parseTutorialHint(InputMessage& msg) +void ProtocolGame::parseTutorialHint(const InputMessagePtr& msg) { - int id = msg.getU8(); // tutorial id + int id = msg->getU8(); // tutorial id g_game.processTutorialHint(id); } -void ProtocolGame::parseAutomapFlag(InputMessage& msg) +void ProtocolGame::parseAutomapFlag(const InputMessagePtr& msg) { // ignored - parsePosition(msg); // position - msg.getU8(); // icon - msg.getString(); // message + getPosition(msg); // position + msg->getU8(); // icon + msg->getString(); // message } -void ProtocolGame::parseQuestLog(InputMessage& msg) +void ProtocolGame::parseQuestLog(const InputMessagePtr& msg) { std::vector> questList; - int questsCount = msg.getU16(); + int questsCount = msg->getU16(); for(int i = 0; i < questsCount; i++) { - int id = msg.getU16(); - std::string name = msg.getString(); - bool completed = msg.getU8(); + int id = msg->getU16(); + std::string name = msg->getString(); + bool completed = msg->getU8(); questList.push_back(std::make_tuple(id, name, completed)); } g_game.processQuestLog(questList); } -void ProtocolGame::parseQuestLine(InputMessage& msg) +void ProtocolGame::parseQuestLine(const InputMessagePtr& msg) { std::vector> questMissions; - int questId = msg.getU16(); - int missionCount = msg.getU8(); + int questId = msg->getU16(); + int missionCount = msg->getU8(); for(int i = 0; i < missionCount; i++) { - std::string missionName = msg.getString(); - std::string missionDescrition = msg.getString(); + std::string missionName = msg->getString(); + std::string missionDescrition = msg->getString(); questMissions.push_back(std::make_tuple(missionName, missionDescrition)); } g_game.processQuestLine(questId, questMissions); } -void ProtocolGame::parseChannelEvent(InputMessage& msg) +void ProtocolGame::parseChannelEvent(const InputMessagePtr& msg) { - msg.getU16(); // channel id - msg.getString(); // player name - msg.getU8(); // event type + msg->getU16(); // channel id + msg->getString(); // player name + msg->getU8(); // event type } -void ProtocolGame::parseItemInfo(InputMessage& msg) +void ProtocolGame::parseItemInfo(const InputMessagePtr& msg) { //TODO } -void ProtocolGame::parsePlayerInventory(InputMessage& msg) +void ProtocolGame::parsePlayerInventory(const InputMessagePtr& msg) { //TODO } -void ProtocolGame::parseExtendedOpcode(InputMessage& msg) +void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg) { - int opcode = msg.getU8(); - std::string buffer = msg.getString(); + int opcode = msg->getU8(); + std::string buffer = msg->getString(); callLuaField("onExtendedOpcode", opcode, buffer); } -void ProtocolGame::setMapDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height) +void ProtocolGame::setMapDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height) { - int startz, endz, zstep, skip = 0; + int startz, endz, zstep; if(z > Otc::SEA_FLOOR) { startz = z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE; @@ -1227,14 +1230,13 @@ void ProtocolGame::setMapDescription(InputMessage& msg, int32 x, int32 y, int32 zstep = -1; } + int skip = 0; for(int nz = startz; nz != endz + zstep; nz += zstep) - setFloorDescription(msg, x, y, nz, width, height, z - nz, &skip); + skip = setFloorDescription(msg, x, y, nz, width, height, z - nz, skip); } -void ProtocolGame::setFloorDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height, int32 offset, int32* skipTiles) +int ProtocolGame::setFloorDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height, int offset, int skip) { - int skip = *skipTiles; - for(int nx = 0; nx < width; nx++) { for(int ny = 0; ny < height; ny++) { Position tilePos(x + nx + offset, y + ny + offset, z); @@ -1243,30 +1245,32 @@ void ProtocolGame::setFloorDescription(InputMessage& msg, int32 x, int32 y, int3 g_map.cleanTile(tilePos); if(skip == 0) { - int tileOpt = msg.getU16(true); + int tileOpt = msg->getU16(true); if(tileOpt >= 0xFF00) - skip = (msg.getU16() & 0xFF); + skip = (msg->getU16() & 0xFF); else { setTileDescription(msg, tilePos); - skip = (msg.getU16() & 0xFF); + skip = (msg->getU16() & 0xFF); } } else skip--; } } - *skipTiles = skip; + return skip; } -void ProtocolGame::setTileDescription(InputMessage& msg, Position position) +void ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position position) { #if PROTOCOL>=910 - msg.getU16(); // environment effect + msg->getU16(); // environment effect #endif + g_map.cleanTile(position); + int stackPos = 0; while(true) { - int inspectItemId = msg.getU16(true); + int inspectItemId = msg->getU16(true); if(inspectItemId >= 0xFF00) { return; } @@ -1274,25 +1278,25 @@ void ProtocolGame::setTileDescription(InputMessage& msg, Position position) if(stackPos >= 10) logTraceError("too many things, stackpos=", stackPos, " pos=", position); - ThingPtr thing = internalGetThing(msg); + ThingPtr thing = getThing(msg); g_map.addThing(thing, position, -1); } stackPos++; } } -Outfit ProtocolGame::internalGetOutfit(InputMessage& msg) +Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg) { Outfit outfit; - int lookType = msg.getU16(); + int lookType = msg->getU16(); if(lookType != 0) { outfit.setCategory(ThingsType::Creature); - int head = msg.getU8(); - int body = msg.getU8(); - int legs = msg.getU8(); - int feet = msg.getU8(); - int addons = msg.getU8(); + int head = msg->getU8(); + int body = msg->getU8(); + int legs = msg->getU8(); + int feet = msg->getU8(); + int addons = msg->getU8(); outfit.setId(lookType); outfit.setHead(head); @@ -1302,7 +1306,7 @@ Outfit ProtocolGame::internalGetOutfit(InputMessage& msg) outfit.setAddons(addons); } else { - int lookTypeEx = msg.getU16(); + int lookTypeEx = msg->getU16(); if(lookTypeEx == 0) { outfit.setCategory(ThingsType::Effect); outfit.setId(13); @@ -1314,51 +1318,51 @@ Outfit ProtocolGame::internalGetOutfit(InputMessage& msg) } #if PROTOCOL>=870 - msg.getU16(); // mount + msg->getU16(); // mount #endif return outfit; } -ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) +ThingPtr ProtocolGame::getThing(const InputMessagePtr& msg) { ThingPtr thing; - int id = msg.getU16(); + int id = msg->getU16(); if(id == 0) Fw::throwException("invalid thing id"); else if(id == Proto::UnknownCreature || id == Proto::OutdatedCreature || id == Proto::Creature) - thing = internalGetCreature(msg, id); + thing = getCreature(msg, id); else // item - thing = internalGetItem(msg, id); + thing = getItem(msg, id); return thing; } -CreaturePtr ProtocolGame::internalGetCreature(InputMessage& msg, int type) +CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) { if(type == 0) - type = msg.getU16(); + type = msg->getU16(); CreaturePtr creature; bool known = (type != Proto::UnknownCreature); if(type == Proto::OutdatedCreature || type == Proto::UnknownCreature) { if(known) { - uint id = msg.getU32(); + uint id = msg->getU32(); creature = g_map.getCreatureById(id); if(!creature) logTraceError("server said that a creature is known, but it's not"); } else { - uint removeId = msg.getU32(); + uint removeId = msg->getU32(); g_map.removeCreatureById(removeId); - uint id = msg.getU32(); + uint id = msg->getU32(); int creatureType; #if PROTOCOL>=910 - creatureType = msg.getU8(); + creatureType = msg->getU8(); #else if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId) creatureType = Proto::CreatureTypePlayer; @@ -1368,7 +1372,7 @@ CreaturePtr ProtocolGame::internalGetCreature(InputMessage& msg, int type) creatureType = Proto::CreatureTypeNpc; #endif - std::string name = msg.getString(); + std::string name = msg->getString(); // every creature name must start with a capital letter if(name.length() > 0) @@ -1393,17 +1397,17 @@ CreaturePtr ProtocolGame::internalGetCreature(InputMessage& msg, int type) } } - int healthPercent = msg.getU8(); - Otc::Direction direction = (Otc::Direction)msg.getU8(); - Outfit outfit = internalGetOutfit(msg); + int healthPercent = msg->getU8(); + Otc::Direction direction = (Otc::Direction)msg->getU8(); + Outfit outfit = getOutfit(msg); Light light; - light.intensity = msg.getU8(); - light.color = msg.getU8(); + light.intensity = msg->getU8(); + light.color = msg->getU8(); - int speed = msg.getU16(); - int skull = msg.getU8(); - int shield = msg.getU8(); + int speed = msg->getU16(); + int skull = msg->getU8(); + int shield = msg->getU8(); // emblem is sent only when the creature is not known int emblem = -1; @@ -1411,9 +1415,9 @@ CreaturePtr ProtocolGame::internalGetCreature(InputMessage& msg, int type) #if PROTOCOL>=854 if(!known) - emblem = msg.getU8(); + emblem = msg->getU8(); - passable = (msg.getU8() == 0); + passable = (msg->getU8() == 0); #endif if(creature) { @@ -1432,10 +1436,10 @@ CreaturePtr ProtocolGame::internalGetCreature(InputMessage& msg, int type) m_localPlayer->setKnown(true); } } else if(type == Proto::Creature) { - uint id = msg.getU32(); - Otc::Direction direction = (Otc::Direction)msg.getU8(); + uint id = msg->getU32(); + Otc::Direction direction = (Otc::Direction)msg->getU8(); #if PROTOCOL>=953 - msg.getU8(); // passable + msg->getU8(); // passable #endif creature = g_map.getCreatureById(id); @@ -1450,34 +1454,34 @@ CreaturePtr ProtocolGame::internalGetCreature(InputMessage& msg, int type) return creature; } -ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id) +ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id) { if(id == 0) - id = msg.getU16(); + id = msg->getU16(); ItemPtr item = Item::create(id); if(item->getId() == 0) Fw::throwException("unable to create item with invalid id"); if(item->isStackable() || item->isFluidContainer() || item->isFluid()) - item->setCountOrSubType(msg.getU8()); + item->setCountOrSubType(msg->getU8()); #if PROTOCOL>=910 if(item->getAnimationPhases() > 1) { // 0xfe => random phase // 0xff => async? - msg.getU8(); + msg->getU8(); } #endif return item; } -Position ProtocolGame::parsePosition(InputMessage& msg) +Position ProtocolGame::getPosition(const InputMessagePtr& msg) { - uint16 x = msg.getU16(); - uint16 y = msg.getU16(); - uint8 z = msg.getU8(); + uint16 x = msg->getU16(); + uint16 y = msg->getU16(); + uint8 z = msg->getU8(); return Position(x, y, z); } diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index 4f841183..57293c2c 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -21,68 +21,72 @@ */ #include "protocolgame.h" -#include +#include + +void ProtocolGame::send(const OutputMessagePtr& outputMessage) +{ + // avoid usage of automated sends (bot modules) + if(!g_game.checkBotProtection()) + return; + Protocol::send(outputMessage); +} + +void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer) +{ + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientExtendedOpcode); + msg->addU8(opcode); + msg->addString(buffer); + send(msg); +} -/* - ClientEquipObject - ClientRefreshContainer - ClientMount - ClientRuleViolationReport - ClientGetItemInfo - ClientMarketLeave - ClientMarketBrowse - ClientMarketCreate - ClientMarketCancel - ClientMarketAccept - ClientExtendedOpcode = 254 // otclient only - */ void ProtocolGame::sendLoginPacket(uint challangeTimestamp, uint8 challangeRandom) { - OutputMessage msg; + OutputMessagePtr msg(new OutputMessage); - msg.addU8(Proto::ClientEnterGame); - msg.addU16(Proto::ClientOs); - msg.addU16(Proto::ClientVersion); + msg->addU8(Proto::ClientEnterGame); + msg->addU16(Proto::ClientOs); + msg->addU16(Proto::ClientVersion); int paddingBytes = 128; - msg.addU8(0); // first RSA byte must be 0 + msg->addU8(0); // first RSA byte must be 0 paddingBytes -= 1; // xtea key generateXteaKey(); - msg.addU32(m_xteaKey[0]); - msg.addU32(m_xteaKey[1]); - msg.addU32(m_xteaKey[2]); - msg.addU32(m_xteaKey[3]); - msg.addU8(0); // is gm set? + msg->addU32(m_xteaKey[0]); + msg->addU32(m_xteaKey[1]); + msg->addU32(m_xteaKey[2]); + msg->addU32(m_xteaKey[3]); + msg->addU8(0); // is gm set? paddingBytes -= 17; #if PROTOCOL>=854 enableChecksum(); - msg.addString(m_accountName); + msg->addString(m_accountName); paddingBytes -= 2 + m_accountName.length(); - msg.addString(m_characterName); + msg->addString(m_characterName); paddingBytes -= 2 + m_characterName.length(); - msg.addString(m_accountPassword); + msg->addString(m_accountPassword); paddingBytes -= 2 + m_accountPassword.length(); - msg.addU32(challangeTimestamp); - msg.addU8(challangeRandom); + msg->addU32(challangeTimestamp); + msg->addU8(challangeRandom); paddingBytes -= 5; #else // PROTOCOL>=810 - msg.addU32(Fw::fromstring(m_accountName)); - msg.addString(m_characterName); - msg.addString(m_accountPassword); + msg->addU32(Fw::fromstring(m_accountName)); + msg->addString(m_characterName); + msg->addString(m_accountPassword); paddingBytes -= 8 + m_characterName.length() + m_accountPassword.length(); #endif // complete the 128 bytes for rsa encryption with zeros - msg.addPaddingBytes(paddingBytes); + msg->addPaddingBytes(paddingBytes); // encrypt with RSA - Rsa::encrypt((char*)msg.getWriteBuffer() - 128, 128, Proto::RSA); + msg->encryptRSA(128, Proto::RSA); send(msg); @@ -91,30 +95,30 @@ void ProtocolGame::sendLoginPacket(uint challangeTimestamp, uint8 challangeRando void ProtocolGame::sendLogout() { - OutputMessage msg; - msg.addU8(Proto::ClientLeaveGame); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientLeaveGame); send(msg); } void ProtocolGame::sendPing() { - OutputMessage msg; - msg.addU8(Proto::ClientPing); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientPing); send(msg); } void ProtocolGame::sendPingBack() { - OutputMessage msg; - msg.addU8(Proto::ClientPingBack); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientPingBack); send(msg); } void ProtocolGame::sendAutoWalk(const std::vector& path) { - OutputMessage msg; - msg.addU8(Proto::ClientAutoWalk); - msg.addU8(path.size()); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientAutoWalk); + msg->addU8(path.size()); for(Otc::Direction dir : path) { uint8 byte; switch(dir) { @@ -146,283 +150,283 @@ void ProtocolGame::sendAutoWalk(const std::vector& path) byte = 0; break; } - msg.addU8(byte); + msg->addU8(byte); } send(msg); } void ProtocolGame::sendWalkNorth() { - OutputMessage msg; - msg.addU8(Proto::ClientWalkNorth); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientWalkNorth); send(msg); } void ProtocolGame::sendWalkEast() { - OutputMessage msg; - msg.addU8(Proto::ClientWalkEast); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientWalkEast); send(msg); } void ProtocolGame::sendWalkSouth() { - OutputMessage msg; - msg.addU8(Proto::ClientWalkSouth); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientWalkSouth); send(msg); } void ProtocolGame::sendWalkWest() { - OutputMessage msg; - msg.addU8(Proto::ClientWalkWest); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientWalkWest); send(msg); } void ProtocolGame::sendStop() { - OutputMessage msg; - msg.addU8(Proto::ClientStop); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientStop); send(msg); } void ProtocolGame::sendWalkNorthEast() { - OutputMessage msg; - msg.addU8(Proto::ClientWalkNorthEast); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientWalkNorthEast); send(msg); } void ProtocolGame::sendWalkSouthEast() { - OutputMessage msg; - msg.addU8(Proto::ClientWalkSouthEast); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientWalkSouthEast); send(msg); } void ProtocolGame::sendWalkSouthWest() { - OutputMessage msg; - msg.addU8(Proto::ClientWalkSouthWest); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientWalkSouthWest); send(msg); } void ProtocolGame::sendWalkNorthWest() { - OutputMessage msg; - msg.addU8(Proto::ClientWalkNorthWest); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientWalkNorthWest); send(msg); } void ProtocolGame::sendTurnNorth() { - OutputMessage msg; - msg.addU8(Proto::ClientTurnNorth); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientTurnNorth); send(msg); } void ProtocolGame::sendTurnEast() { - OutputMessage msg; - msg.addU8(Proto::ClientTurnEast); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientTurnEast); send(msg); } void ProtocolGame::sendTurnSouth() { - OutputMessage msg; - msg.addU8(Proto::ClientTurnSouth); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientTurnSouth); send(msg); } void ProtocolGame::sendTurnWest() { - OutputMessage msg; - msg.addU8(Proto::ClientTurnWest); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientTurnWest); send(msg); } void ProtocolGame::sendEquipItem(int itemId, int countOrSubType) { - OutputMessage msg; - msg.addU8(Proto::ClientEquipItem); - msg.addU16(itemId); - msg.addU8(countOrSubType); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientEquipItem); + msg->addU16(itemId); + msg->addU8(countOrSubType); send(msg); } void ProtocolGame::sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count) { - OutputMessage msg; - msg.addU8(Proto::ClientMove); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientMove); addPosition(msg, fromPos); - msg.addU16(thingId); - msg.addU8(stackpos); + msg->addU16(thingId); + msg->addU8(stackpos); addPosition(msg, toPos); - msg.addU8(count); + msg->addU8(count); send(msg); } void ProtocolGame::sendInspectNpcTrade(int itemId, int count) { - OutputMessage msg; - msg.addU8(Proto::ClientInspectNpcTrade); - msg.addU16(itemId); - msg.addU8(count); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientInspectNpcTrade); + msg->addU16(itemId); + msg->addU8(count); send(msg); } void ProtocolGame::sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack) { - OutputMessage msg; - msg.addU8(Proto::ClientBuyItem); - msg.addU16(itemId); - msg.addU8(subType); - msg.addU8(amount); - msg.addU8(ignoreCapacity ? 0x01 : 0x00); - msg.addU8(buyWithBackpack ? 0x01 : 0x00); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientBuyItem); + msg->addU16(itemId); + msg->addU8(subType); + msg->addU8(amount); + msg->addU8(ignoreCapacity ? 0x01 : 0x00); + msg->addU8(buyWithBackpack ? 0x01 : 0x00); send(msg); } void ProtocolGame::sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped) { - OutputMessage msg; - msg.addU8(Proto::ClientSellItem); - msg.addU16(itemId); - msg.addU8(subType); - msg.addU8(amount); - msg.addU8(ignoreEquipped ? 0x01 : 0x00); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientSellItem); + msg->addU16(itemId); + msg->addU8(subType); + msg->addU8(amount); + msg->addU8(ignoreEquipped ? 0x01 : 0x00); send(msg); } void ProtocolGame::sendCloseNpcTrade() { - OutputMessage msg; - msg.addU8(Proto::ClientCloseNpcTrade); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientCloseNpcTrade); send(msg); } void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, uint creatureId) { - OutputMessage msg; - msg.addU8(Proto::ClientRequestTrade); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRequestTrade); addPosition(msg, pos); - msg.addU16(thingId); - msg.addU8(stackpos); - msg.addU32(creatureId); + msg->addU16(thingId); + msg->addU8(stackpos); + msg->addU32(creatureId); send(msg); } void ProtocolGame::sendInspectTrade(bool counterOffer, int index) { - OutputMessage msg; - msg.addU8(Proto::ClientInspectTrade); - msg.addU8(counterOffer ? 0x01 : 0x00); - msg.addU8(index); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientInspectTrade); + msg->addU8(counterOffer ? 0x01 : 0x00); + msg->addU8(index); send(msg); } void ProtocolGame::sendAcceptTrade() { - OutputMessage msg; - msg.addU8(Proto::ClientAcceptTrade); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientAcceptTrade); send(msg); } void ProtocolGame::sendRejectTrade() { - OutputMessage msg; - msg.addU8(Proto::ClientRejectTrade); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRejectTrade); send(msg); } void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpos, int index) { - OutputMessage msg; - msg.addU8(Proto::ClientUseItem); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientUseItem); addPosition(msg, position); - msg.addU16(itemId); - msg.addU8(stackpos); - msg.addU8(index); + msg->addU16(itemId); + msg->addU8(stackpos); + msg->addU8(index); send(msg); } void ProtocolGame::sendUseItemWith(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos) { - OutputMessage msg; - msg.addU8(Proto::ClientUseItemWith); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientUseItemWith); addPosition(msg, fromPos); - msg.addU16(itemId); - msg.addU8(fromStackpos); + msg->addU16(itemId); + msg->addU8(fromStackpos); addPosition(msg, toPos); - msg.addU16(toThingId); - msg.addU8(toStackpos); + msg->addU16(toThingId); + msg->addU8(toStackpos); send(msg); } void ProtocolGame::sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId) { - OutputMessage msg; - msg.addU8(Proto::ClientUseOnCreature); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientUseOnCreature); addPosition(msg, pos); - msg.addU16(thingId); - msg.addU8(stackpos); - msg.addU32(creatureId); + msg->addU16(thingId); + msg->addU8(stackpos); + msg->addU32(creatureId); send(msg); } void ProtocolGame::sendRotateItem(const Position& pos, int thingId, int stackpos) { - OutputMessage msg; - msg.addU8(Proto::ClientRotateItem); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRotateItem); addPosition(msg, pos); - msg.addU16(thingId); - msg.addU8(stackpos); + msg->addU16(thingId); + msg->addU8(stackpos); send(msg); } void ProtocolGame::sendCloseContainer(int containerId) { - OutputMessage msg; - msg.addU8(Proto::ClientCloseContainer); - msg.addU8(containerId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientCloseContainer); + msg->addU8(containerId); send(msg); } void ProtocolGame::sendUpContainer(int containerId) { - OutputMessage msg; - msg.addU8(Proto::ClientUpContainer); - msg.addU8(containerId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientUpContainer); + msg->addU8(containerId); send(msg); } void ProtocolGame::sendEditText(uint id, const std::string& text) { - OutputMessage msg; - msg.addU8(Proto::ClientEditText); - msg.addU32(id); - msg.addString(text); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientEditText); + msg->addU32(id); + msg->addString(text); send(msg); } void ProtocolGame::sendEditList(uint id, int doorId, const std::string& text) { - OutputMessage msg; - msg.addU8(Proto::ClientEditList); - msg.addU8(doorId); - msg.addU32(id); - msg.addString(text); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientEditList); + msg->addU8(doorId); + msg->addU32(id); + msg->addString(text); send(msg); } void ProtocolGame::sendLook(const Position& position, int thingId, int stackpos) { - OutputMessage msg; - msg.addU8(Proto::ClientLook); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientLook); addPosition(msg, position); - msg.addU16(thingId); - msg.addU8(stackpos); + msg->addU16(thingId); + msg->addU8(stackpos); send(msg); } @@ -433,304 +437,295 @@ void ProtocolGame::sendTalk(Otc::SpeakType speakType, int channelId, const std:: int serverSpeakType = Proto::translateSpeakTypeToServer(speakType); - OutputMessage msg; - msg.addU8(Proto::ClientTalk); - msg.addU8(serverSpeakType); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientTalk); + msg->addU8(serverSpeakType); switch(serverSpeakType) { case Proto::ServerSpeakPrivateFrom: case Proto::ServerSpeakPrivateRedFrom: - msg.addString(receiver); + msg->addString(receiver); break; case Proto::ServerSpeakChannelYellow: case Proto::ServerSpeakChannelRed: - msg.addU16(channelId); + msg->addU16(channelId); break; } - msg.addString(message); + msg->addString(message); send(msg); } void ProtocolGame::sendRequestChannels() { - OutputMessage msg; - msg.addU8(Proto::ClientRequestChannels); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRequestChannels); send(msg); } void ProtocolGame::sendJoinChannel(int channelId) { - OutputMessage msg; - msg.addU8(Proto::ClientJoinChannel); - msg.addU16(channelId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientJoinChannel); + msg->addU16(channelId); send(msg); } void ProtocolGame::sendLeaveChannel(int channelId) { - OutputMessage msg; - msg.addU8(Proto::ClientLeaveChannel); - msg.addU16(channelId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientLeaveChannel); + msg->addU16(channelId); send(msg); } void ProtocolGame::sendOpenPrivateChannel(const std::string& receiver) { - OutputMessage msg; - msg.addU8(Proto::ClientOpenPrivateChannel); - msg.addString(receiver); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientOpenPrivateChannel); + msg->addString(receiver); send(msg); } void ProtocolGame::sendCloseNpcChannel() { - OutputMessage msg; - msg.addU8(Proto::ClientCloseNpcChannel); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientCloseNpcChannel); send(msg); } void ProtocolGame::sendChangeFightModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight) { - OutputMessage msg; - msg.addU8(Proto::ClientChangeFightModes); - msg.addU8(fightMode); - msg.addU8(chaseMode); - msg.addU8(safeFight ? 0x01: 0x00); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientChangeFightModes); + msg->addU8(fightMode); + msg->addU8(chaseMode); + msg->addU8(safeFight ? 0x01: 0x00); send(msg); } void ProtocolGame::sendAttack(uint creatureId) { - OutputMessage msg; - msg.addU8(Proto::ClientAttack); - msg.addU32(creatureId); - msg.addU32(0); - msg.addU32(0); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientAttack); + msg->addU32(creatureId); + msg->addU32(0); + msg->addU32(0); send(msg); } void ProtocolGame::sendFollow(uint creatureId) { - OutputMessage msg; - msg.addU8(Proto::ClientFollow); - msg.addU32(creatureId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientFollow); + msg->addU32(creatureId); send(msg); } void ProtocolGame::sendInviteToParty(uint creatureId) { - OutputMessage msg; - msg.addU8(Proto::ClientInviteToParty); - msg.addU32(creatureId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientInviteToParty); + msg->addU32(creatureId); send(msg); } void ProtocolGame::sendJoinParty(uint creatureId) { - OutputMessage msg; - msg.addU8(Proto::ClientJoinParty); - msg.addU32(creatureId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientJoinParty); + msg->addU32(creatureId); send(msg); } void ProtocolGame::sendRevokeInvitation(uint creatureId) { - OutputMessage msg; - msg.addU8(Proto::ClientRevokeInvitation); - msg.addU32(creatureId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRevokeInvitation); + msg->addU32(creatureId); send(msg); } void ProtocolGame::sendPassLeadership(uint creatureId) { - OutputMessage msg; - msg.addU8(Proto::ClientPassLeadership); - msg.addU32(creatureId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientPassLeadership); + msg->addU32(creatureId); send(msg); } void ProtocolGame::sendLeaveParty() { - OutputMessage msg; - msg.addU8(Proto::ClientLeaveParty); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientLeaveParty); send(msg); } void ProtocolGame::sendShareExperience(bool active, int unknown) { - OutputMessage msg; - msg.addU8(Proto::ClientShareExperience); - msg.addU8(active ? 0x01 : 0x00); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientShareExperience); + msg->addU8(active ? 0x01 : 0x00); #if PROTOCOL<910 - msg.addU8(unknown); + msg->addU8(unknown); #endif send(msg); } void ProtocolGame::sendOpenOwnChannel() { - OutputMessage msg; - msg.addU8(Proto::ClientOpenOwnChannel); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientOpenOwnChannel); send(msg); } void ProtocolGame::sendInviteToOwnChannel(const std::string& name) { - OutputMessage msg; - msg.addU8(Proto::ClientInviteToOwnChannel); - msg.addString(name); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientInviteToOwnChannel); + msg->addString(name); send(msg); } void ProtocolGame::sendExcludeFromOwnChannel(const std::string& name) { - OutputMessage msg; - msg.addU8(Proto::ClientExcludeFromOwnChannel); - msg.addString(name); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientExcludeFromOwnChannel); + msg->addString(name); send(msg); } void ProtocolGame::sendCancelAttackAndFollow() { - OutputMessage msg; - msg.addU8(Proto::ClientCancelAttackAndFollow); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientCancelAttackAndFollow); send(msg); } void ProtocolGame::sendRefreshContainer() { - OutputMessage msg; - msg.addU8(Proto::ClientRefreshContainer); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRefreshContainer); send(msg); } void ProtocolGame::sendRequestOutfit() { - OutputMessage msg; - msg.addU8(Proto::ClientRequestOutfit); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRequestOutfit); send(msg); } void ProtocolGame::sendChangeOutfit(const Outfit& outfit) { - OutputMessage msg; - msg.addU8(Proto::ClientChangeOutfit); - msg.addU16(outfit.getId()); - msg.addU8(outfit.getHead()); - msg.addU8(outfit.getBody()); - msg.addU8(outfit.getLegs()); - msg.addU8(outfit.getFeet()); - msg.addU8(outfit.getAddons()); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientChangeOutfit); + msg->addU16(outfit.getId()); + msg->addU8(outfit.getHead()); + msg->addU8(outfit.getBody()); + msg->addU8(outfit.getLegs()); + msg->addU8(outfit.getFeet()); + msg->addU8(outfit.getAddons()); send(msg); } void ProtocolGame::sendMount(bool mount) { - OutputMessage msg; - msg.addU8(Proto::ClientMount); - msg.addU8(mount); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientMount); + msg->addU8(mount); send(msg); } void ProtocolGame::sendAddVip(const std::string& name) { - OutputMessage msg; - msg.addU8(Proto::ClientAddVip); - msg.addString(name); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientAddVip); + msg->addString(name); send(msg); } void ProtocolGame::sendRemoveVip(uint playerId) { - OutputMessage msg; - msg.addU8(Proto::ClientRemoveVip); - msg.addU32(playerId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRemoveVip); + msg->addU32(playerId); send(msg); } void ProtocolGame::sendBugReport(const std::string& comment) { - OutputMessage msg; - msg.addU8(Proto::ClientBugReport); - msg.addString(comment); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientBugReport); + msg->addString(comment); send(msg); } void ProtocolGame::sendRuleVilation(const std::string& target, int reason, int action, const std::string& comment, const std::string& statement, int statementId, bool ipBanishment) { - OutputMessage msg; - msg.addU8(Proto::ClientRuleViolation); - msg.addString(target); - msg.addU8(reason); - msg.addU8(action); - msg.addString(comment); - msg.addString(statement); - msg.addU16(statementId); - msg.addU8(ipBanishment); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRuleViolation); + msg->addString(target); + msg->addU8(reason); + msg->addU8(action); + msg->addString(comment); + msg->addString(statement); + msg->addU16(statementId); + msg->addU8(ipBanishment); send(msg); } void ProtocolGame::sendDebugReport(const std::string& a, const std::string& b, const std::string& c, const std::string& d) { - OutputMessage msg; - msg.addU8(Proto::ClientDebugReport); - msg.addString(a); - msg.addString(b); - msg.addString(c); - msg.addString(d); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientDebugReport); + msg->addString(a); + msg->addString(b); + msg->addString(c); + msg->addString(d); send(msg); } void ProtocolGame::sendRequestQuestLog() { - OutputMessage msg; - msg.addU8(Proto::ClientRequestQuestLog); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRequestQuestLog); send(msg); } void ProtocolGame::sendRequestQuestLine(int questId) { - OutputMessage msg; - msg.addU8(Proto::ClientRequestQuestLine); - msg.addU16(questId); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRequestQuestLine); + msg->addU16(questId); send(msg); } void ProtocolGame::sendNewNewRuleViolation(int reason, int action, const std::string& characterName, const std::string& comment, const std::string& translation) { - OutputMessage msg; - msg.addU8(Proto::ClientNewRuleViolation); - msg.addU8(reason); - msg.addU8(action); - msg.addString(characterName); - msg.addString(comment); - msg.addString(translation); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientNewRuleViolation); + msg->addU8(reason); + msg->addU8(action); + msg->addString(characterName); + msg->addString(comment); + msg->addString(translation); send(msg); } void ProtocolGame::sendRequestItemInfo(int itemId, int index) { - OutputMessage msg; - msg.addU8(Proto::ClientRequestItemInfo); - msg.addU8(1); // count, 1 for just one item - msg.addU16(itemId); - msg.addU8(index); - send(msg); -} - -void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer) -{ - OutputMessage msg; - msg.addU8(Proto::ClientExtendedOpcode); - msg.addU8(opcode); - msg.addString(buffer); + OutputMessagePtr msg(new OutputMessage); + msg->addU8(Proto::ClientRequestItemInfo); + msg->addU8(1); // count, 1 for just one item + msg->addU16(itemId); + msg->addU8(index); send(msg); } -void ProtocolGame::addPosition(OutputMessage& msg, const Position& position) +void ProtocolGame::addPosition(const OutputMessagePtr& msg, const Position& position) { - msg.addU16(position.x); - msg.addU16(position.y); - msg.addU8(position.z); + msg->addU16(position.x); + msg->addU16(position.y); + msg->addU8(position.z); } diff --git a/src/otclient/net/protocollogin.cpp b/src/otclient/net/protocollogin.cpp index 9409dd66..8aa9b16a 100644 --- a/src/otclient/net/protocollogin.cpp +++ b/src/otclient/net/protocollogin.cpp @@ -22,7 +22,6 @@ #include "protocollogin.h" #include -#include #include #include #include @@ -46,23 +45,23 @@ void ProtocolLogin::onConnect() sendLoginPacket(); } -void ProtocolLogin::onRecv(InputMessage& inputMessage) +void ProtocolLogin::onRecv(const InputMessagePtr& msg) { try { - while(!inputMessage.eof()) { - int opcode = inputMessage.getU8(); + while(!msg->eof()) { + int opcode = msg->getU8(); switch(opcode) { case Proto::LoginServerError: - parseError(inputMessage); + parseError(msg); break; case Proto::LoginServerMotd: - parseMOTD(inputMessage); + parseMOTD(msg); break; case Proto::LoginServerUpdateNeeded: callLuaField("onError", "Client needs update."); break; case Proto::LoginServerCharacterList: - parseCharacterList(inputMessage); + parseCharacterList(msg); break; default: Fw::throwException("unknown opt byte ", opcode); @@ -83,76 +82,76 @@ void ProtocolLogin::onError(const boost::system::error_code& error) void ProtocolLogin::sendLoginPacket() { - OutputMessage msg; + OutputMessagePtr msg(new OutputMessage); - msg.addU8(Proto::ClientEnterAccount); - msg.addU16(Proto::ClientOs); - msg.addU16(Proto::ClientVersion); + msg->addU8(Proto::ClientEnterAccount); + msg->addU16(Proto::ClientOs); + msg->addU16(Proto::ClientVersion); - msg.addU32(g_thingsType.getSignature()); // data signature - msg.addU32(g_sprites.getSignature()); // sprite signature - msg.addU32(Proto::PicSignature); // pic signature + msg->addU32(g_thingsType.getSignature()); // data signature + msg->addU32(g_sprites.getSignature()); // sprite signature + msg->addU32(Proto::PicSignature); // pic signature int paddingBytes = 128; - msg.addU8(0); // first RSA byte must be 0 + msg->addU8(0); // first RSA byte must be 0 paddingBytes -= 1; // xtea key generateXteaKey(); - msg.addU32(m_xteaKey[0]); - msg.addU32(m_xteaKey[1]); - msg.addU32(m_xteaKey[2]); - msg.addU32(m_xteaKey[3]); + msg->addU32(m_xteaKey[0]); + msg->addU32(m_xteaKey[1]); + msg->addU32(m_xteaKey[2]); + msg->addU32(m_xteaKey[3]); paddingBytes -= 16; #if PROTOCOL>=854 enableChecksum(); - msg.addString(m_accountName); - msg.addString(m_accountPassword); + msg->addString(m_accountName); + msg->addString(m_accountPassword); paddingBytes -= 4 + m_accountName.length() + m_accountPassword.length(); #elif PROTOCOL>=810 - msg.addU32(Fw::fromstring(m_accountName)); - msg.addString(m_accountPassword); + msg->addU32(Fw::fromstring(m_accountName)); + msg->addString(m_accountPassword); paddingBytes -= 6 + m_accountPassword.length(); #endif - msg.addPaddingBytes(paddingBytes); // complete the 128 bytes for rsa encryption with zeros - Rsa::encrypt((char*)msg.getWriteBuffer() - 128, 128, Proto::RSA); + msg->addPaddingBytes(paddingBytes); // complete the 128 bytes for rsa encryption with zeros + msg->encryptRSA(128, Proto::RSA); send(msg); enableXteaEncryption(); recv(); } -void ProtocolLogin::parseError(InputMessage& inputMessage) +void ProtocolLogin::parseError(const InputMessagePtr& msg) { - std::string error = inputMessage.getString(); + std::string error = msg->getString(); callLuaField("onError", error, false); } -void ProtocolLogin::parseMOTD(InputMessage& inputMessage) +void ProtocolLogin::parseMOTD(const InputMessagePtr& msg) { - std::string motd = inputMessage.getString(); + std::string motd = msg->getString(); callLuaField("onMotd", motd); } -void ProtocolLogin::parseCharacterList(InputMessage& inputMessage) +void ProtocolLogin::parseCharacterList(const InputMessagePtr& msg) { typedef std::tuple CharacterInfo; typedef std::vector CharaterList; CharaterList charList; - int numCharacters = inputMessage.getU8(); + int numCharacters = msg->getU8(); for(int i = 0; i < numCharacters; ++i) { - std::string name = inputMessage.getString(); - std::string world = inputMessage.getString(); - uint32 ip = inputMessage.getU32(); - uint16 port = inputMessage.getU16(); + std::string name = msg->getString(); + std::string world = msg->getString(); + uint32 ip = msg->getU32(); + uint16 port = msg->getU16(); charList.push_back(CharacterInfo(name, world, Fw::ip2str(ip), port)); } - int premDays = inputMessage.getU16(); + int premDays = msg->getU16(); callLuaField("onCharacterList", charList, premDays); } diff --git a/src/otclient/net/protocollogin.h b/src/otclient/net/protocollogin.h index d1eef585..9d1320df 100644 --- a/src/otclient/net/protocollogin.h +++ b/src/otclient/net/protocollogin.h @@ -38,7 +38,7 @@ public: void cancelLogin() { disconnect(); } void onConnect(); - void onRecv(InputMessage& inputMessage); + void onRecv(const InputMessagePtr& inputMessage); void onError(const boost::system::error_code& error); ProtocolLoginPtr asProtocolLogin() { return std::static_pointer_cast(shared_from_this()); } @@ -46,9 +46,9 @@ public: private: void sendLoginPacket(); - void parseError(InputMessage& inputMessage); - void parseMOTD(InputMessage& inputMessage); - void parseCharacterList(InputMessage& inputMessage); + void parseError(const InputMessagePtr& inputMessage); + void parseMOTD(const InputMessagePtr& inputMessage); + void parseCharacterList(const InputMessagePtr& inputMessage); std::string m_accountName, m_accountPassword;