2011-04-20 08:40:31 +02:00
|
|
|
#ifndef PROTOCOL_H
|
|
|
|
#define PROTOCOL_H
|
|
|
|
|
2011-07-28 01:01:33 +02:00
|
|
|
#include "netdeclarations.h"
|
|
|
|
#include "inputmessage.h"
|
|
|
|
#include "outputmessage.h"
|
2011-04-20 08:40:31 +02:00
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
#include <luascript/luaobject.h>
|
2011-07-27 20:10:49 +02:00
|
|
|
|
2011-07-27 01:13:27 +02:00
|
|
|
class Protocol : public LuaObject
|
2011-04-20 08:40:31 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Protocol();
|
|
|
|
|
2011-07-27 20:10:49 +02:00
|
|
|
void connect(const std::string& host, uint16 port);
|
2011-08-01 06:28:41 +02:00
|
|
|
void send(OutputMessage& outputMessage);
|
2011-07-27 20:10:49 +02:00
|
|
|
void recv();
|
2011-07-28 01:01:33 +02:00
|
|
|
void internalRecvHeader(uint8* buffer, uint16 size);
|
|
|
|
void internalRecvData(uint8* buffer, uint16 size);
|
2011-04-20 08:40:31 +02:00
|
|
|
|
2011-07-27 20:10:49 +02:00
|
|
|
virtual void onConnect() = 0;
|
2011-08-01 06:28:41 +02:00
|
|
|
virtual void onRecv(InputMessage& inputMessage) = 0;
|
2011-07-13 23:12:36 +02:00
|
|
|
virtual void onError(const boost::system::error_code& err);
|
2011-04-20 08:40:31 +02:00
|
|
|
|
2011-07-27 20:10:49 +02:00
|
|
|
ProtocolPtr asProtocol() { return std::static_pointer_cast<Protocol>(shared_from_this()); }
|
|
|
|
|
2011-05-30 05:11:12 +02:00
|
|
|
protected:
|
|
|
|
uint32 m_xteaKey[4];
|
2011-08-01 06:28:41 +02:00
|
|
|
bool m_checksumEnabled, m_xteaEncryptionEnabled;
|
2011-07-27 20:10:49 +02:00
|
|
|
InputMessage m_inputMessage;
|
2011-05-30 05:11:12 +02:00
|
|
|
|
2011-04-20 08:40:31 +02:00
|
|
|
private:
|
2011-08-01 06:28:41 +02:00
|
|
|
bool xteaDecrypt(InputMessage& inputMessage);
|
|
|
|
void xteaEncrypt(OutputMessage& outputMessage);
|
2011-07-28 01:01:33 +02:00
|
|
|
uint32 getAdlerChecksum(uint8* buffer, uint16 size);
|
2011-05-30 05:11:12 +02:00
|
|
|
|
2011-04-20 08:40:31 +02:00
|
|
|
ConnectionPtr m_connection;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|