Some changes to server compatibility
This commit is contained in:
parent
4c369bc823
commit
c969f5209f
|
@ -41,6 +41,10 @@
|
|||
#include <framework/ui/ui.h>
|
||||
#endif
|
||||
|
||||
#ifdef FW_NET
|
||||
#include <framework/net/server.h>
|
||||
#endif
|
||||
|
||||
void Application::registerLuaFunctions()
|
||||
{
|
||||
// conversion globals
|
||||
|
@ -622,6 +626,11 @@ void Application::registerLuaFunctions()
|
|||
#endif
|
||||
|
||||
#ifdef FW_NET
|
||||
// Server
|
||||
g_lua.registerClass<Server>();
|
||||
g_lua.bindClassStaticFunction<Server>("create", &Server::create);
|
||||
g_lua.bindClassMemberFunction<Server>("acceptNext", &Server::acceptNext);
|
||||
|
||||
// Protocol
|
||||
g_lua.registerClass<Protocol>();
|
||||
g_lua.bindClassStaticFunction<Protocol>("create", []{ return ProtocolPtr(new Protocol); });
|
||||
|
@ -629,6 +638,8 @@ void Application::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<Protocol>("disconnect", &Protocol::disconnect);
|
||||
g_lua.bindClassMemberFunction<Protocol>("isConnected", &Protocol::isConnected);
|
||||
g_lua.bindClassMemberFunction<Protocol>("isConnecting", &Protocol::isConnecting);
|
||||
g_lua.bindClassMemberFunction<Protocol>("getConnection", &Protocol::getConnection);
|
||||
g_lua.bindClassMemberFunction<Protocol>("setConnection", &Protocol::setConnection);
|
||||
g_lua.bindClassMemberFunction<Protocol>("send", &Protocol::send);
|
||||
g_lua.bindClassMemberFunction<Protocol>("recv", &Protocol::recv);
|
||||
g_lua.bindClassMemberFunction<Protocol>("getXteaKey", &Protocol::getXteaKey);
|
||||
|
|
|
@ -25,10 +25,11 @@
|
|||
|
||||
#include "declarations.h"
|
||||
#include <boost/asio.hpp>
|
||||
#include <framework/luaengine/luaobject.h>
|
||||
#include <framework/core/timer.h>
|
||||
#include <framework/core/declarations.h>
|
||||
|
||||
class Connection : public stdext::shared_object
|
||||
class Connection : public LuaObject
|
||||
{
|
||||
typedef std::function<void(const boost::system::error_code&)> ErrorCallback;
|
||||
typedef std::function<void(uint8*, uint16)> RecvCallback;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "declarations.h"
|
||||
#include "inputmessage.h"
|
||||
#include "outputmessage.h"
|
||||
#include "connection.h"
|
||||
|
||||
#include <framework/luaengine/luaobject.h>
|
||||
|
||||
|
@ -41,6 +42,8 @@ public:
|
|||
|
||||
bool isConnected();
|
||||
bool isConnecting();
|
||||
ConnectionPtr getConnection() { return m_connection; }
|
||||
void setConnection(const ConnectionPtr& connection) { m_connection = connection; }
|
||||
|
||||
void generateXteaKey();
|
||||
std::vector<int> getXteaKey();
|
||||
|
|
|
@ -25,12 +25,17 @@
|
|||
|
||||
extern asio::io_service g_ioService;
|
||||
|
||||
Server::Server(uint16 port)
|
||||
Server::Server(int port)
|
||||
: m_acceptor(g_ioService, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port))
|
||||
{
|
||||
}
|
||||
|
||||
void Server::acceptNext(const AcceptCallback& acceptCallback)
|
||||
ServerPtr Server::create(int port)
|
||||
{
|
||||
return ServerPtr(new Server(port));
|
||||
}
|
||||
|
||||
void Server::acceptNext()
|
||||
{
|
||||
ConnectionPtr connection = ConnectionPtr(new Connection);
|
||||
connection->m_connecting = true;
|
||||
|
@ -39,6 +44,6 @@ void Server::acceptNext(const AcceptCallback& acceptCallback)
|
|||
connection->m_connected = true;
|
||||
connection->m_connecting = false;
|
||||
}
|
||||
acceptCallback(connection, error);
|
||||
callLuaField("onAccept", connection, error.message(), error.value());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -24,15 +24,17 @@
|
|||
#define SERVER_H
|
||||
|
||||
#include "declarations.h"
|
||||
#include <framework/luaengine/luaobject.h>
|
||||
|
||||
class Server
|
||||
class Server : public LuaObject
|
||||
{
|
||||
typedef std::function<void(ConnectionPtr, const boost::system::error_code&)> AcceptCallback;
|
||||
|
||||
public:
|
||||
Server(uint16 port);
|
||||
Server(int port);
|
||||
static ServerPtr create(int port);
|
||||
|
||||
void acceptNext(const AcceptCallback& acceptCallback);
|
||||
void acceptNext();
|
||||
|
||||
private:
|
||||
asio::ip::tcp::acceptor m_acceptor;
|
||||
|
|
Loading…
Reference in New Issue