tibia-client/src/framework/net/protocol.h

83 lines
2.8 KiB
C
Raw Normal View History

2011-08-28 15:17:58 +02:00
/*
2014-04-01 07:36:42 +02:00
* Copyright (c) 2010-2014 OTClient <https://github.com/edubart/otclient>
2011-08-28 15:17:58 +02:00
*
* 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.
*/
2011-04-20 08:40:31 +02:00
#ifndef PROTOCOL_H
#define PROTOCOL_H
2011-08-15 16:06:15 +02:00
#include "declarations.h"
2011-07-28 01:01:33 +02:00
#include "inputmessage.h"
#include "outputmessage.h"
2012-07-30 21:40:03 +02:00
#include "connection.h"
2011-04-20 08:40:31 +02:00
#include <framework/luaengine/luaobject.h>
2011-07-27 20:10:49 +02:00
2012-06-22 05:14:13 +02:00
// @bindclass
class Protocol : public LuaObject
2011-04-20 08:40:31 +02:00
{
public:
Protocol();
2012-01-13 16:41:57 +01:00
virtual ~Protocol();
2011-04-20 08:40:31 +02:00
2011-07-27 20:10:49 +02:00
void connect(const std::string& host, uint16 port);
2011-08-16 02:30:31 +02:00
void disconnect();
2011-08-29 20:38:01 +02:00
bool isConnected();
bool isConnecting();
2013-03-14 00:55:20 +01:00
ticks_t getElapsedTicksSinceLastRead() { return m_connection ? m_connection->getElapsedTicksSinceLastRead() : -1; }
2012-07-30 21:40:03 +02:00
ConnectionPtr getConnection() { return m_connection; }
void setConnection(const ConnectionPtr& connection) { m_connection = connection; }
2011-08-29 20:38:01 +02:00
2012-06-05 21:16:57 +02:00
void generateXteaKey();
2012-08-02 02:24:54 +02:00
void setXteaKey(uint32 a, uint32 b, uint32 c, uint32 d);
2012-06-05 21:16:57 +02:00
std::vector<int> getXteaKey();
void enableXteaEncryption() { m_xteaEncryptionEnabled = true; }
2011-08-16 02:30:31 +02:00
2012-06-05 21:16:57 +02:00
void enableChecksum() { m_checksumEnabled = true; }
2012-06-05 21:16:57 +02:00
virtual void send(const OutputMessagePtr& outputMessage);
2012-08-22 10:51:31 +02:00
virtual void recv();
2011-04-20 08:40:31 +02:00
ProtocolPtr asProtocol() { return static_self_cast<Protocol>(); }
2011-04-20 08:40:31 +02:00
2012-06-05 21:16:57 +02:00
protected:
virtual void onConnect();
2012-06-05 23:27:37 +02:00
virtual void onRecv(const InputMessagePtr& inputMessage);
virtual void onError(const boost::system::error_code& err);
2011-08-16 05:27:46 +02:00
2011-05-30 05:11:12 +02:00
uint32 m_xteaKey[4];
2011-04-20 08:40:31 +02:00
private:
void internalRecvHeader(uint8* buffer, uint16 size);
void internalRecvData(uint8* buffer, uint16 size);
bool xteaDecrypt(const InputMessagePtr& inputMessage);
void xteaEncrypt(const OutputMessagePtr& outputMessage);
2011-05-30 05:11:12 +02:00
2011-08-16 05:27:46 +02:00
bool m_checksumEnabled;
bool m_xteaEncryptionEnabled;
2011-04-20 08:40:31 +02:00
ConnectionPtr m_connection;
InputMessagePtr m_inputMessage;
2011-04-20 08:40:31 +02:00
};
#endif