Mercurial > malikania
view libclient/malikania/client/client.cpp @ 92:4031eda60e11
Misc: switch to JSON, #650
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 07 Jun 2017 20:44:37 +0200 |
parents | |
children | 103c1e4ba2c2 |
line wrap: on
line source
/* * client.cpp -- main client game clas * * Copyright (c) 2013-2017 Malikania Authors * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <iostream> #include "client.hpp" #include "connection.hpp" #include "state.hpp" namespace mlk { namespace client { client::client(boost::asio::io_service& service, mlk::client::connection& connection) noexcept : service_(service) , connection_(connection) { } client::~client() noexcept = default; void client::handle_error(boost::system::error_code) { // TODO: add error } void client::handle_connect(boost::system::error_code) { connection_.do_read(*this); } void client::handle_read(boost::system::error_code, nlohmann::json msg) { connection_.do_read(*this); if (state_) { state_->handle_message(*this, std::move(msg)); } } void client::connect(std::string host, uint16_t port) { connection_.do_connect(*this, std::move(host), port); } } // !client } // !mlk