new script engine, and things maybe be bugged for a while

This commit is contained in:
Eduardo Bart
2011-07-26 20:13:27 -03:00
parent ab7394f357
commit 70f0b0dace
137 changed files with 2905 additions and 2578 deletions

View File

@@ -40,61 +40,57 @@ void Connection::poll()
ioService.reset();
}
void Connection::connect(const std::string& host, uint16 port, const boost::function<void()>& connectCallback)
void Connection::connect(const std::string& host, uint16 port, const std::function<void()>& connectCallback)
{
m_connectCallback = connectCallback;
m_connectionState = CONNECTION_STATE_RESOLVING;
boost::asio::ip::tcp::resolver::query query(host, convert<std::string>(port));
m_resolver.async_resolve(query, boost::bind(&Connection::onResolve, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::iterator));
m_resolver.async_resolve(query, std::bind(&Connection::onResolve, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
m_timer.expires_from_now(boost::posix_time::seconds(2));
m_timer.async_wait(boost::bind(&Connection::onTimeout, shared_from_this(), boost::asio::placeholders::error));
m_timer.async_wait(std::bind(&Connection::onTimeout, shared_from_this(), std::placeholders::_1));
}
void Connection::send(OutputMessage *outputMessage)
{
boost::asio::async_write(m_socket,
boost::asio::buffer(outputMessage->getBuffer(), outputMessage->getMessageSize()),
boost::bind(&Connection::onSend, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
std::bind(&Connection::onSend, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
m_timer.expires_from_now(boost::posix_time::seconds(2));
m_timer.async_wait(boost::bind(&Connection::onTimeout, shared_from_this(), boost::asio::placeholders::error));
m_timer.async_wait(std::bind(&Connection::onTimeout, shared_from_this(), std::placeholders::_1));
}
void Connection::onTimeout(const boost::system::error_code& error)
{
if(error != boost::asio::error::operation_aborted)
g_dispatcher.addTask(boost::bind(m_errorCallback, error));
g_dispatcher.addTask(std::bind(m_errorCallback, error));
}
void Connection::onResolve(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpointIterator)
{
trace();
m_timer.cancel();
if(error) {
if(m_errorCallback)
g_dispatcher.addTask(boost::bind(m_errorCallback, error));
g_dispatcher.addTask(std::bind(m_errorCallback, error));
return;
}
m_socket.async_connect(*endpointIterator, boost::bind(&Connection::onConnect, shared_from_this(), boost::asio::placeholders::error));
m_socket.async_connect(*endpointIterator, std::bind(&Connection::onConnect, shared_from_this(), std::placeholders::_1));
m_timer.expires_from_now(boost::posix_time::seconds(2));
m_timer.async_wait(boost::bind(&Connection::onTimeout, shared_from_this(), boost::asio::placeholders::error));
m_timer.async_wait(std::bind(&Connection::onTimeout, shared_from_this(), std::placeholders::_1));
}
void Connection::onConnect(const boost::system::error_code& error)
{
trace();
m_timer.cancel();
if(error) {
if(m_errorCallback)
g_dispatcher.addTask(boost::bind(m_errorCallback, error));
g_dispatcher.addTask(std::bind(m_errorCallback, error));
return;
}
@@ -103,29 +99,25 @@ void Connection::onConnect(const boost::system::error_code& error)
// Start listening.
boost::asio::async_read(m_socket,
boost::asio::buffer(m_inputMessage.getBuffer(), InputMessage::HEADER_LENGTH),
boost::bind(&Connection::onRecvHeader, shared_from_this(), boost::asio::placeholders::error));
std::bind(&Connection::onRecvHeader, shared_from_this(), std::placeholders::_1));
}
void Connection::onSend(const boost::system::error_code& error, size_t)
{
trace();
m_timer.cancel();
if(error) {
if(m_errorCallback)
g_dispatcher.addTask(boost::bind(m_errorCallback, error));
g_dispatcher.addTask(std::bind(m_errorCallback, error));
return;
}
}
void Connection::onRecvHeader(const boost::system::error_code& error)
{
trace();
if(error) {
if(m_errorCallback)
g_dispatcher.addTask(boost::bind(m_errorCallback, error));
g_dispatcher.addTask(std::bind(m_errorCallback, error));
return;
}
@@ -134,16 +126,14 @@ void Connection::onRecvHeader(const boost::system::error_code& error)
boost::asio::async_read(m_socket,
boost::asio::buffer(m_inputMessage.getBuffer() + InputMessage::CHECKSUM_POS, messageSize),
boost::bind(&Connection::onRecvData, shared_from_this(), boost::asio::placeholders::error));
std::bind(&Connection::onRecvData, shared_from_this(), std::placeholders::_1));
}
void Connection::onRecvData(const boost::system::error_code& error)
{
trace();
if(error) {
if(m_errorCallback)
g_dispatcher.addTask(boost::bind(m_errorCallback, error));
g_dispatcher.addTask(std::bind(m_errorCallback, error));
return;
}
@@ -151,7 +141,7 @@ void Connection::onRecvData(const boost::system::error_code& error)
// must be called outside dispatcher cause of inputmessage.
if(m_recvCallback)
m_recvCallback(&m_inputMessage);
//g_dispatcher.addTask(boost::bind(m_recvCallback, &m_inputMessage));
//g_dispatcher.addTask(std::bind(m_recvCallback, &m_inputMessage));
// keep reading
@@ -159,6 +149,6 @@ void Connection::onRecvData(const boost::system::error_code& error)
/*m_inputMessage.reset();
boost::asio::async_read(m_socket,
boost::asio::buffer(m_inputMessage.getBuffer(), InputMessage::HEADER_LENGTH),
boost::bind(&Connection::onRecvHeader, shared_from_this(), boost::asio::placeholders::error));*/
std::bind(&Connection::onRecvHeader, shared_from_this(), std::placeholders::_1));*/
}

View File

@@ -31,19 +31,18 @@
#include <net/outputmessage.h>
#include <boost/asio.hpp>
#include <boost/function.hpp>
typedef boost::function<void(boost::system::error_code&)> ErrorCallback;
typedef boost::function<void(InputMessage*)> RecvCallback;
typedef std::function<void(boost::system::error_code&)> ErrorCallback;
typedef std::function<void(InputMessage*)> RecvCallback;
class Connection : public boost::enable_shared_from_this<Connection>, boost::noncopyable
class Connection : public std::enable_shared_from_this<Connection>, boost::noncopyable
{
public:
Connection();
static void poll();
void connect(const std::string& host, uint16 port, const boost::function<void()>& connectCallback);
void connect(const std::string& host, uint16 port, const std::function<void()>& connectCallback);
void send(OutputMessage *outputMessage);
void setErrorCallback(const ErrorCallback& errorCallback) { m_errorCallback = errorCallback; }
@@ -66,7 +65,7 @@ public:
private:
ErrorCallback m_errorCallback;
RecvCallback m_recvCallback;
boost::function<void()> m_connectCallback;
std::function<void()> m_connectCallback;
ConnectionState_t m_connectionState;
boost::asio::deadline_timer m_timer;
@@ -76,6 +75,6 @@ private:
};
typedef boost::shared_ptr<Connection> ConnectionPtr;
typedef std::shared_ptr<Connection> ConnectionPtr;
#endif

View File

@@ -29,12 +29,12 @@
Protocol::Protocol() :
m_connection(new Connection)
{
m_connection->setErrorCallback(boost::bind(&Protocol::onError, this, _1));
m_connection->setRecvCallback(boost::bind(&Protocol::onRecv, this, _1));
m_connection->setErrorCallback(std::bind(&Protocol::onError, this, std::placeholders::_1));
m_connection->setRecvCallback(std::bind(&Protocol::onRecv, this, std::placeholders::_1));
m_xteaEncryptionEnabled = false;
}
void Protocol::connect(const std::string& host, uint16 port, const boost::function<void()>& callback)
void Protocol::connect(const std::string& host, uint16 port, const std::function<void()>& callback)
{
m_connection->connect(host, port, callback);
}

View File

@@ -28,7 +28,7 @@
#include <net/connection.h>
#include <net/inputmessage.h>
#include <net/outputmessage.h>
#include <script/scriptobject.h>
#include <script/luaobject.h>
#define CIPSOFT_PUBLIC_RSA "1321277432058722840622950990822933849527763264961655079678763618" \
"4334395343554449668205332383339435179772895415509701210392836078" \
@@ -38,18 +38,18 @@
//#define RSA "109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110603907230888610072655818825358503429057592827629436413108566029093628212635953836686562675849720620786279431090218017681061521755056710823876476444260558147179707119674283982419152118103759076030616683978566631413"
class Protocol : public ScriptObject
class Protocol : public LuaObject
{
public:
Protocol();
void connect(const std::string& host, uint16 port, const boost::function<void()>& callback);
void connect(const std::string& host, uint16 port, const std::function<void()>& callback);
void send(OutputMessage *outputMessage);
virtual void onRecv(InputMessage *inputMessage);
virtual void onError(const boost::system::error_code& err);
virtual const char *getScriptObjectType() const { return "Protocol"; }
virtual const char* getLuaTypeName() const { return "Protocol"; }
protected:
uint32 m_xteaKey[4];
@@ -63,6 +63,6 @@ private:
ConnectionPtr m_connection;
};
typedef boost::shared_ptr<Protocol> ProtocolPtr;
typedef std::shared_ptr<Protocol> ProtocolPtr;
#endif

View File

@@ -44,6 +44,6 @@ protected:
mpz_t m_p, m_q, m_u, m_d, m_dp, m_dq, m_mod;
};
typedef boost::shared_ptr<Rsa> RsaPtr;
typedef std::shared_ptr<Rsa> RsaPtr;
#endif //RSA_H