net improvments

This commit is contained in:
Eduardo Bart
2011-08-16 00:27:46 -03:00
parent b90bb275b9
commit 3d4cfb793e
11 changed files with 109 additions and 105 deletions

View File

@@ -1,21 +1,23 @@
#include "protocol.h"
#include "connection.h"
Protocol::Protocol() : m_connection(new Connection)
Protocol::Protocol()
{
m_connection->setErrorCallback(std::bind(&Protocol::onError, this, _1));
m_xteaEncryptionEnabled = false;
m_checksumEnabled = true;
m_checksumEnabled = false;
}
void Protocol::connect(const std::string& host, uint16 port)
{
m_connection = ConnectionPtr(new Connection);
m_connection->setErrorCallback(std::bind(&Protocol::onError, asProtocol(), _1));
m_connection->connect(host, port, std::bind(&Protocol::onConnect, asProtocol()));
}
void Protocol::disconnect()
{
m_connection->close();
m_connection.reset();
}
void Protocol::send(OutputMessage& outputMessage)
@@ -76,6 +78,16 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size)
onRecv(m_inputMessage);
}
void Protocol::generateXteaKey()
{
std::mt19937 eng(std::time(NULL));
std::uniform_int_distribution<uint32> unif(0, 0xFFFFFFFF);
m_xteaKey[0] = unif(eng);
m_xteaKey[1] = unif(eng);
m_xteaKey[2] = unif(eng);
m_xteaKey[3] = unif(eng);
}
bool Protocol::xteaDecrypt(InputMessage& inputMessage)
{
// FIXME: this function has not been tested yet