From 99b2f612b7d261541d576be165ce158a1f1413d7 Mon Sep 17 00:00:00 2001 From: Andre Antunes Date: Sat, 9 Apr 2011 22:35:51 -0300 Subject: [PATCH] adding protocoltibia --- src/net/protocoltibia87.cpp | 106 ++++++++++++++++++++++++++++++++++++ src/net/protocoltibia87.h | 55 +++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 src/net/protocoltibia87.cpp create mode 100644 src/net/protocoltibia87.h diff --git a/src/net/protocoltibia87.cpp b/src/net/protocoltibia87.cpp new file mode 100644 index 00000000..8947bf7b --- /dev/null +++ b/src/net/protocoltibia87.cpp @@ -0,0 +1,106 @@ +/* The MIT License + * + * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "protocoltibia87.h" +#include "../framework/util/rsa.h" + +const char* ProtocolTibia87::rsa = "4673033022358411862216018001503683214873298680851934467521055526294025873980576" + "6860224610646919605860206328024326703361630109888417839241959507572247284807035" + "2355696191737922927869078457919049551036016528225191219083671878855092700253886" + "41700821735345222087940578381210879116823013776808975766851829020659073"; + +ProtocolTibia87::ProtocolTibia87() +{ + +} + +void ProtocolTibia87::begin() +{ + connect("icechaw.otland.net", 7171, + [this](){ + this->afterConnect(); + } + ); +} + +void ProtocolTibia87::login(const std::string& account, const std::string& password) +{ + sendAccount(account, password); +} + +void ProtocolTibia87::sendAccount(const std::string& account, const std::string& password) +{ + NetworkMessagePtr networkMessage(new NetworkMessage); + + networkMessage->addByte(0x01);//login Server + networkMessage->addU16(0x00);//OS + networkMessage->addU16(0x00);//VERSION + networkMessage->addPaddingBytes(12);// + + int32 m_notEncriptedLen = networkMessage->getMessageLength(); + + //begin RSA encrypt + networkMessage->addU32(1); //xtea + networkMessage->addU32(2); //xtea + networkMessage->addU32(3); //xtea + networkMessage->addU32(4); //xtea + + networkMessage->addString(account); + networkMessage->addString(password); + + Rsa::encrypt(networkMessage->getBodyBuffer() + m_notEncriptedLen, networkMessage->getMessageLength() - m_notEncriptedLen, ProtocolTibia87::rsa); + + networkMessage->setMessageLength(m_notEncriptedLen + 128); + networkMessage->updateHeaderLength(); + + send(networkMessage, + [this](){ + this->afterSendAccount(); + } + ); +} + +void ProtocolTibia87::afterConnect() +{ + login("9418347", "lollol"); +} + +void ProtocolTibia87::afterSendAccount() +{ + recv( + [this](NetworkMessagePtr networkMessage){ + this->parseCharacterList(networkMessage); + } + ); +} + +void ProtocolTibia87::onError(const boost::system::error_code& error, const std::string& msg) +{ + logError("%s; %s", error.message().c_str(), msg.c_str()); +} + +void ProtocolTibia87::parseCharacterList(NetworkMessagePtr networkMessage) +{ + logInfo("Parsing characters. msglen: %d", networkMessage->getMessageLength()); + +} diff --git a/src/net/protocoltibia87.h b/src/net/protocoltibia87.h new file mode 100644 index 00000000..ddf06651 --- /dev/null +++ b/src/net/protocoltibia87.h @@ -0,0 +1,55 @@ +/* The MIT License + * + * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef PROTOCOLTIBIA87_H +#define PROTOCOLTIBIA87_H + +#include "../framework/prerequisites.h" +#include "../framework/net/protocol.h" + +class ProtocolTibia87 : public Protocol +{ +public: + ProtocolTibia87(); + + virtual void begin(); + +protected: + void login(const std::string& account, const std::string& password); + void sendAccount(const std::string& account, const std::string& password); + void parseCharacterList(NetworkMessagePtr networkMessage); + + void readCharacterList(); + + void afterConnect(); + void afterSendAccount(); + + virtual void onError(const boost::system::error_code& error, const std::string& msg); + +private: + static const char* rsa; +}; + +typedef std::shared_ptr ProtocolTibia87Ptr; + +#endif //PROTOCOLTIBIA87_H \ No newline at end of file