Commit 3360abe2 authored by louiz’'s avatar louiz’

Add RemoteGameClient class and fix some little compile issues.

parent 04374af6
...@@ -198,9 +198,10 @@ if(BUILD_SERVER) ...@@ -198,9 +198,10 @@ if(BUILD_SERVER)
file( file(
GLOB GLOB
source_server source_server
src/network/remote_client.*
src/network/interface_remote_client.*
src/network/command_handler.* src/network/command_handler.*
src/network/interface_remote_client.*
src/network/remote_client.*
src/network/remote_game_client.*
src/network/server.* src/network/server.*
src/network/transfer_sender.* src/network/transfer_sender.*
src/network/command.* src/network/command.*
...@@ -215,6 +216,9 @@ if(BUILD_SERVER) ...@@ -215,6 +216,9 @@ if(BUILD_SERVER)
logging logging
config config
database database
${SFML_LIBRARIES}
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
) )
......
...@@ -26,7 +26,7 @@ void Command::set_name(const std::string name) ...@@ -26,7 +26,7 @@ void Command::set_name(const std::string name)
this->name = name; this->name = name;
} }
inline void Command::set_body_size(int size) void Command::set_body_size(int size)
{ {
this->body_size = size; this->body_size = size;
} }
......
#include <network/command_handler.hpp> #include <network/command_handler.hpp>
#include <network/command.hpp>
CommandHandler::CommandHandler(): CommandHandler::CommandHandler():
writing(false) writing(false)
{ {
} }
CommandHandler::~CommandHandler()
{
}
void CommandHandler::install_callback(const std::string& command, void CommandHandler::install_callback(const std::string& command,
t_read_callback callback) t_read_callback callback)
{ {
......
...@@ -31,7 +31,7 @@ class CommandHandler ...@@ -31,7 +31,7 @@ class CommandHandler
friend void TransferSender::send_next_chunk(); friend void TransferSender::send_next_chunk();
public: public:
CommandHandler(); CommandHandler();
virtual ~CommandHandler() {} virtual ~CommandHandler();
void install_read_handler(); void install_read_handler();
/** /**
......
#include <istream>
#include <network/server.hpp>
#include <network/remote_client.hpp>
// main de test
int main(void)
{
Config::read_conf("../config/server.conf");
Server<RemoteClient> server(7878);
server.run();
return 0;
}
...@@ -65,8 +65,7 @@ private: ...@@ -65,8 +65,7 @@ private:
* It is executed whenever that command is received. * It is executed whenever that command is received.
* See CommandHandler for details * See CommandHandler for details
*/ */
void install_callbacks(); virtual void install_callbacks();
void install_read_handler(void);
void auth_callback(Command*); void auth_callback(Command*);
void transfer_callback(Command*); void transfer_callback(Command*);
/** /**
...@@ -76,7 +75,7 @@ private: ...@@ -76,7 +75,7 @@ private:
Server<RemoteClient>* server; Server<RemoteClient>* server;
User* user; User* user;
/** /**
* A list of all the current file transfers with tha client. * A list of all the current file transfers with the client.
*/ */
std::vector<TransferSender*> senders; std::vector<TransferSender*> senders;
}; };
......
#include <network/remote_game_client.hpp>
RemoteGameClient::RemoteGameClient(boost::asio::io_service& io_service,
Server<RemoteGameClient>* server):
InterfaceRemoteClient(io_service),
server(server)
{
}
RemoteGameClient::~RemoteGameClient()
{
}
void RemoteGameClient::on_connection_closed()
{
this->server->remove_client(this);
}
void RemoteGameClient::install_callbacks()
{
this->install_callback("MOVE", boost::bind(&RemoteGameClient::move_callback, this, _1));
}
void RemoteGameClient::move_callback(Command* command)
{
log_debug("move command");
}
boost::asio::io_service& RemoteGameClient::get_io_service()
{
return this->server->io_service;
}
/** @addtogroup Network
* @{
*/
/**
* @class RemoteGameClient
*/
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#ifndef __REMOTE_GAME_CLIENT_HPP__
# define __REMOTE_GAME_CLIENT_HPP__
#include <network/interface_remote_client.hpp>
#include <network/server.hpp>
#include <database/user.hpp>
using boost::asio::ip::tcp;
class RemoteGameClient: public InterfaceRemoteClient
{
public:
RemoteGameClient(boost::asio::io_service&, Server<RemoteGameClient>*);
~RemoteGameClient();
virtual void on_connection_closed();
virtual boost::asio::io_service& get_io_service();
private:
/**
* Creates the default callbacks associated with a network command.
* It is executed whenever that command is received.
* See CommandHandler for details
*/
virtual void install_callbacks();
void install_read_handler(void);
void move_callback(Command*);
/**
* A pointer to the server, to call its method when the RemoteGameClient
* has to be deleted.
*/
Server<RemoteGameClient>* server;
};
#endif
/**@}*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment