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

75 lines
2.4 KiB
C
Raw Normal View History

2011-08-28 15:17:58 +02:00
/*
2012-01-02 17:58:37 +01:00
* Copyright (c) 2010-2012 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"
2011-04-20 08:40:31 +02:00
2011-08-15 16:06:15 +02:00
#include <framework/luascript/luaobject.h>
2011-07-27 20:10:49 +02:00
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();
virtual void send(const OutputMessagePtr& outputMessage);
2011-08-16 02:30:31 +02:00
ProtocolPtr asProtocol() { return std::static_pointer_cast<Protocol>(shared_from_this()); }
protected:
void recv();
2011-04-20 08:40:31 +02:00
2011-07-27 20:10:49 +02:00
virtual void onConnect() = 0;
virtual void onRecv(const InputMessagePtr& inputMessage) = 0;
2011-08-16 02:30:31 +02:00
virtual void onError(const boost::system::error_code& err) = 0;
2011-04-20 08:40:31 +02:00
2011-08-16 05:27:46 +02:00
void enableChecksum() { m_checksumEnabled = true; }
void enableXteaEncryption() { m_xteaEncryptionEnabled = true; }
void generateXteaKey();
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