mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 20:43:26 +02:00
protocol login at lua
This commit is contained in:
@@ -46,6 +46,7 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindGlobalFunction("pointtostring", [](const Point& v) { return stdext::to_string(v); });
|
||||
g_lua.bindGlobalFunction("colortostring", [](const Color& v) { return stdext::to_string(v); });
|
||||
g_lua.bindGlobalFunction("sizetostring", [](const Size& v) { return stdext::to_string(v); });
|
||||
g_lua.bindGlobalFunction("iptostring", [](int v) { return stdext::ip_to_string(v); });
|
||||
|
||||
g_lua.registerStaticClass("g_crypt");
|
||||
g_lua.bindClassStaticFunction("g_crypt", "encrypt", Crypt::encrypt);
|
||||
@@ -397,11 +398,17 @@ void Application::registerLuaFunctions()
|
||||
|
||||
// Protocol
|
||||
g_lua.registerClass<Protocol>();
|
||||
//g_lua.bindClassMemberFunction<Protocol>("connect", &Protocol::connect);
|
||||
g_lua.bindClassStaticFunction<Protocol>("create", []{ return ProtocolPtr(new Protocol); });
|
||||
g_lua.bindClassMemberFunction<Protocol>("connect", &Protocol::connect);
|
||||
g_lua.bindClassMemberFunction<Protocol>("disconnect", &Protocol::disconnect);
|
||||
g_lua.bindClassMemberFunction<Protocol>("isConnected", &Protocol::isConnected);
|
||||
g_lua.bindClassMemberFunction<Protocol>("isConnecting", &Protocol::isConnecting);
|
||||
g_lua.bindClassMemberFunction<Protocol>("send", &Protocol::send);
|
||||
g_lua.bindClassMemberFunction<Protocol>("send", &Protocol::send); // must change to safeSend
|
||||
g_lua.bindClassMemberFunction<Protocol>("recv", &Protocol::recv);
|
||||
g_lua.bindClassMemberFunction<Protocol>("getXteaKey", &Protocol::getXteaKey);
|
||||
g_lua.bindClassMemberFunction<Protocol>("generateXteaKey", &Protocol::generateXteaKey);
|
||||
g_lua.bindClassMemberFunction<Protocol>("enableXteaEncryption", &Protocol::enableXteaEncryption);
|
||||
g_lua.bindClassMemberFunction<Protocol>("enableChecksum", &Protocol::enableChecksum);
|
||||
|
||||
// Module
|
||||
g_lua.registerClass<Module>();
|
||||
|
@@ -151,6 +151,15 @@ void Protocol::generateXteaKey()
|
||||
m_xteaKey[3] = unif(eng);
|
||||
}
|
||||
|
||||
std::vector<int> Protocol::getXteaKey()
|
||||
{
|
||||
std::vector<int> xteaKey;
|
||||
xteaKey.resize(4);
|
||||
for(int i = 0; i < 4; ++i)
|
||||
xteaKey[i] = m_xteaKey[i];
|
||||
return xteaKey;
|
||||
}
|
||||
|
||||
bool Protocol::xteaDecrypt(const InputMessagePtr& inputMessage)
|
||||
{
|
||||
uint16 encryptedSize = inputMessage->getUnreadSize();
|
||||
@@ -215,3 +224,8 @@ void Protocol::xteaEncrypt(const OutputMessagePtr& outputMessage)
|
||||
readPos = readPos + 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Protocol::onConnect()
|
||||
{
|
||||
callLuaField("onConnect");
|
||||
}
|
||||
|
@@ -41,20 +41,21 @@ public:
|
||||
bool isConnected();
|
||||
bool isConnecting();
|
||||
|
||||
void generateXteaKey();
|
||||
std::vector<int> getXteaKey();
|
||||
void enableXteaEncryption() { m_xteaEncryptionEnabled = true; }
|
||||
|
||||
void enableChecksum() { m_checksumEnabled = true; }
|
||||
|
||||
virtual void send(const OutputMessagePtr& outputMessage);
|
||||
void recv();
|
||||
|
||||
ProtocolPtr asProtocol() { return std::static_pointer_cast<Protocol>(shared_from_this()); }
|
||||
|
||||
protected:
|
||||
void recv();
|
||||
|
||||
virtual void onConnect() = 0;
|
||||
virtual void onRecv(const InputMessagePtr& inputMessage) = 0;
|
||||
virtual void onError(const boost::system::error_code& err) = 0;
|
||||
|
||||
void enableChecksum() { m_checksumEnabled = true; }
|
||||
void enableXteaEncryption() { m_xteaEncryptionEnabled = true; }
|
||||
void generateXteaKey();
|
||||
virtual void onConnect();
|
||||
virtual void onRecv(const InputMessagePtr& inputMessage) {}
|
||||
virtual void onError(const boost::system::error_code& err) {}
|
||||
|
||||
uint32 m_xteaKey[4];
|
||||
|
||||
|
Reference in New Issue
Block a user