Commit b41a5f17 authored by louiz’'s avatar louiz’

Compile server with config and logging, and update all macros to new version.

parent 163832c2
......@@ -5,12 +5,12 @@
Game::Game()
{
log_info << "Launching game" << std::endl;
log_info("Launching game");
}
Game::~Game()
{
log_info << "End." << std::endl;
log_info("End.");
}
void Game::on_login_form_validated(const std::string& login,
......@@ -25,13 +25,13 @@ void Game::on_login_form_validated(const std::string& login,
void Game::on_connection_failed(const std::string& host, const short& port)
{
log_debug << "Connection to remote " << host << ":" << port << " failed" << std::endl;
log_debug("Connection to remote " << host << ":" << port << " failed");
}
void Game::on_connection_success(const std::string& login, const std::string& password)
{
log_debug << "Login in..." << std::endl;
log_debug("Login in...");
this->authenticate(login, password);
}
......@@ -42,7 +42,7 @@ void Game::authenticate(const std::string& login, const std::string& password)
void Game::on_authenticate(const std::string& result)
{
log_debug << "on_authenticate " << result << std::endl;
log_debug("on_authenticate ");
}
void Game::run()
......
all: server client
server:
g++ command_handler.cpp server.cpp remote_client.cpp -lboost_system -L/usr/include/boost -lpthread -o server
g++ command_handler.cpp server.cpp remote_client.cpp ../logging/logging.cpp ../config/config.cpp -lboost_system -L/usr/include/boost -lpthread -o server
client:
g++ client.cpp -lboost_system -L/usr/include/boost -lpthread -o client
g++ client.cpp -lboost_system -L/usr/include/boost ../logging/logging.cpp ../config/config.cpp -lpthread -o client
.PHONY: server client
......@@ -9,7 +9,7 @@ Client::~Client()
{
if (this->socket->is_open())
{
log_debug << "Closing connection" << std::endl;
log_debug("Closing connection");
this->socket->close();
}
delete this->socket;
......@@ -23,7 +23,7 @@ void Client::connect(const std::string& host,
{
// TODO use resolve and DNS
tcp::endpoint endpoint(boost::asio::ip::address::from_string(host), port);
log_info << "Connecting" << std::endl;
log_info("Connecting");
this->socket->async_connect(endpoint,
boost::bind(&Client::connect_handler, this,
on_success, on_failure,
......@@ -36,13 +36,13 @@ void Client::connect_handler(boost::function< void(void) > on_success,
{
if (error)
{
log_info << "Connection failed: " << error << std::endl;
log_info("Connection failed: " << error);
if (on_failure)
on_failure();
}
else
{
log_info << "Connected." << std::endl;
log_info("Connected.");
this->install_read_handler();
if (on_success)
on_success();
......
......@@ -7,21 +7,21 @@ CommandHandler::CommandHandler()
void CommandHandler::install_callback(const std::string& command,
boost::function< void(std::string) > callback)
{
log_debug << "installing callback for command " << command << std::endl;
log_debug("installing callback for command " << command);
this->callbacks[command] = callback;
}
void CommandHandler::install_callback_once(const std::string& command,
boost::function< void(std::string) > callback)
{
log_debug << "installing ONCE callback for command " << command << std::endl;
log_debug("installing ONCE callback for command " << command);
this->callbacks_once[command] = callback;
}
boost::function< void(std::string) > CommandHandler::get_callback(const std::string& command)
{
log_debug << "get_callback" << std::endl;
log_debug("get_callback");
std::map<const std::string, boost::function< void(std::string) > >::iterator it;
it = this->callbacks.find(command);
......@@ -31,7 +31,7 @@ boost::function< void(std::string) > CommandHandler::get_callback(const std::str
it = this->callbacks_once.find(command);
if (it != this->callbacks_once.end())
{
log_debug << "Removing callback for command " << command << std::endl;
log_debug("Removing callback for command " << command);
boost::function< void(std::string) > callback = it->second;
this->callbacks_once.erase(it);
return callback;
......@@ -41,7 +41,7 @@ boost::function< void(std::string) > CommandHandler::get_callback(const std::str
void CommandHandler::read_handler(const boost::system::error_code& error, std::size_t bytes_transferred)
{
log_debug << "read_handler, size: " << bytes_transferred << " bytes. error: " << error << std::endl;
log_debug("read_handler, size: " << bytes_transferred << " bytes. error: " << error);
if (error)
{
......@@ -53,7 +53,7 @@ void CommandHandler::read_handler(const boost::system::error_code& error, std::s
this->data.sgetn(c, bytes_transferred);
c[bytes_transferred] = 0;
log_debug << "Received: [" << c << "] " << this->data.size() << std::endl;
log_debug("Received: [" << c << "] " << this->data.size());
// find the . separator
size_t pos = 0;
while (c[pos] && c[pos] != '.')
......@@ -71,7 +71,7 @@ void CommandHandler::read_handler(const boost::system::error_code& error, std::s
command = std::string(c, pos);
size = atoi(std::string(c+pos+1, bytes_transferred-pos-2).data()); // remove the ending :
}
log_debug << command << " . " << size << std::endl;
log_debug(command << " . " << size);
// Find out if a callback was registered for that command.
boost::function< void(std::string) > callback = this->get_callback(command);
......@@ -91,15 +91,15 @@ void CommandHandler::binary_read_handler(const boost::system::error_code& error,
// std::size_t size,
boost::function<void(std::string)> callback)
{
log_debug << "binary_read_handler" << bytes_transferred << std::endl;
log_debug("binary_read_handler" << bytes_transferred);
char c[bytes_transferred+1];
this->data.sgetn(c, bytes_transferred);
c[bytes_transferred] = 0;
log_debug << "[" << c << "]" << std::endl;
log_debug("[" << c << "]");
if (callback)
callback(c);
else
log_debug << "no callback" << std::endl;
log_debug("no callback");
this->install_read_handler();
}
......@@ -136,12 +136,12 @@ void CommandHandler::send(const char* msg)
boost::bind(&CommandHandler::send_handler, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
log_debug << "Sending [" << msg << "]" << std::endl;
log_debug("Sending [" << msg << "]");
}
void CommandHandler::send_handler(const boost::system::error_code& error,
std::size_t bytes_transferred)
{
// TODO check for error
log_debug << bytes_transferred << " bytes sent" << std::endl;
log_debug(bytes_transferred << " bytes sent");
}
......@@ -3,6 +3,8 @@
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include "../logging/logging.hpp"
#ifndef __COMMAND_HANDLER_HPP__
# define __COMMAND_HANDLER_HPP__
......
......@@ -10,7 +10,7 @@ RemoteClient::RemoteClient(boost::asio::io_service& io_service):
RemoteClient::~RemoteClient()
{
log_info << "Deleting remote client" << std::endl;
log_info("Deleting remote client");
delete this->socket;
}
......@@ -26,7 +26,7 @@ void RemoteClient::install_callbacks()
void RemoteClient::auth_callback(const std::string& arg)
{
log_debug << "auth_callback: " << arg << std::endl;
log_debug("auth_callback: " << arg);
// TODO check login for user, check if it is already logged,
// set it as logged in the database, and return 0 if it failed and 1
// if it succeded
......@@ -35,7 +35,7 @@ void RemoteClient::auth_callback(const std::string& arg)
void RemoteClient::start(void)
{
log_debug << "Starting RemoteClient " << this->number << std::endl;
log_debug("Starting RemoteClient " << this->number);
CommandHandler::install_read_handler();
this->install_callbacks();
}
......@@ -9,7 +9,7 @@ Server::Server(short port):
Server::~Server()
{
log_debug << "closing socket" << std::endl;
log_debug("closing socket");
delete this->acceptor;
}
......@@ -33,7 +33,7 @@ void Server::accept(void)
error = this->acceptor->listen(512, error);
if (error)
{
log_error << "Error on listen() [" << error << "]. Exiting." << std::endl;
log_error("Error on listen() [" << error << "]. Exiting.");
return;
}
this->install_accept_handler();
......@@ -54,6 +54,7 @@ void Server::run()
// main de test
int main(void)
{
Config::read_conf("../config/batajelo.conf");
Server server(7878);
server.run();
return 0;
......
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