changeset 150:308c792763ef

Misc: various cleanups
author David Demelier <markand@malikania.fr>
date Mon, 04 Dec 2017 12:17:45 +0100
parents dece83c24c64
children 7a8ccd50bdf6
files libclient/malikania/client/client.cpp libclient/malikania/client/client.hpp libclient/malikania/client/connection.cpp libclient/malikania/client/connection.hpp libclient/malikania/client/state/map_state.cpp libclient/malikania/client/state/splashscreen_state.cpp libserver-test/malikania/server/db/test_spell.hpp
diffstat 7 files changed, 19 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libclient/malikania/client/client.cpp	Thu Oct 26 20:03:23 2017 +0200
+++ b/libclient/malikania/client/client.cpp	Mon Dec 04 12:17:45 2017 +0100
@@ -27,11 +27,10 @@
 
 namespace client {
 
-client::client(boost::asio::io_service& service,
+client::client(boost::asio::io_service&,
                mlk::client::connection& connection,
                mlk::client::window& window) noexcept
-    : service_(service)
-    , connection_(connection)
+    : connection_(connection)
     , window_(window)
 {
 }
--- a/libclient/malikania/client/client.hpp	Thu Oct 26 20:03:23 2017 +0200
+++ b/libclient/malikania/client/client.hpp	Mon Dec 04 12:17:45 2017 +0100
@@ -45,7 +45,6 @@
  */
 class client : public dispatcher {
 private:
-    boost::asio::io_service& service_;
     mlk::client::connection& connection_;
     mlk::client::window& window_;
     std::unique_ptr<state> state_;
--- a/libclient/malikania/client/connection.cpp	Thu Oct 26 20:03:23 2017 +0200
+++ b/libclient/malikania/client/connection.cpp	Mon Dec 04 12:17:45 2017 +0100
@@ -30,7 +30,6 @@
     : service_(service)
     , context_(boost::asio::ssl::context::sslv23)
     , resolver_(service_)
-    , socket_(service_, context_)
 {
 }
 
@@ -40,7 +39,7 @@
  */
 void connection::handshake(connect_t handler)
 {
-    socket_.async_handshake(boost::asio::ssl::stream_base::client, std::move(handler));
+    socket_->async_handshake(boost::asio::ssl::stream_base::client, std::move(handler));
 }
 
 /*
@@ -54,7 +53,7 @@
 
     auto buffer = boost::asio::buffer(std::get<1>(output_[0]));
 
-    boost::asio::async_write(socket_, buffer, [this] (auto code, auto xfer) {
+    boost::asio::async_write(*socket_, buffer, [this] (auto code, auto xfer) {
         auto& handler = std::get<2>(output_[0]);
 
         if (handler)
@@ -71,6 +70,8 @@
  */
 void connection::connect(const std::string& host, std::uint16_t port, connect_t handler)
 {
+    socket_ = std::make_unique<socket_t>(service_, context_);
+
     using tcp = boost::asio::ip::tcp;
 
     auto str = std::to_string(port);
@@ -79,7 +80,7 @@
         if (code)
             handler(std::move(code));
         else {
-            boost::asio::async_connect(socket_.lowest_layer(), ep, [this, handler] (auto code, auto) {
+            boost::asio::async_connect(socket_->lowest_layer(), ep, [this, handler] (auto code, auto) {
                 if (code)
                     handler(std::move(code));
                 else
@@ -95,6 +96,7 @@
  */
 void connection::send(nlohmann::json message, send_t handler)
 {
+    assert(socket_);
     assert(message.is_object());
 
     auto in_progress = !output_.empty();
@@ -112,13 +114,15 @@
  */
 void connection::read(recv_t handler)
 {
+    assert(socket_);
+
 #if !defined(NDEBUG)
     assert(!is_reading);
 
     is_reading = true;
 #endif
 
-    boost::asio::async_read_until(socket_, input_, "\r\n\r\n", [this, handler] (auto code, auto xfer) {
+    boost::asio::async_read_until(*socket_, input_, "\r\n\r\n", [this, handler] (auto code, auto xfer) {
 #if !defined(NDEBUG)
         is_reading = false;
 #endif
--- a/libclient/malikania/client/connection.hpp	Thu Oct 26 20:03:23 2017 +0200
+++ b/libclient/malikania/client/connection.hpp	Mon Dec 04 12:17:45 2017 +0100
@@ -65,10 +65,12 @@
      */
     using output_item_t = std::tuple<nlohmann::json, std::string, send_t>;
 
+    using socket_t = boost::asio::ssl::stream<boost::asio::ip::tcp::socket>;
+
     boost::asio::io_service& service_;
     boost::asio::ssl::context context_;
     boost::asio::ip::tcp::resolver resolver_;
-    boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_;
+    std::unique_ptr<socket_t> socket_;
     boost::asio::streambuf input_;
     std::deque<output_item_t> output_;
 
--- a/libclient/malikania/client/state/map_state.cpp	Thu Oct 26 20:03:23 2017 +0200
+++ b/libclient/malikania/client/state/map_state.cpp	Mon Dec 04 12:17:45 2017 +0100
@@ -30,7 +30,7 @@
         delta_ = {0, delta_.y()};
 }
 
-void map_state::update(client& clt)
+void map_state::update(client&)
 {
     position_ = {
         position_.x() + delta_.x(),
--- a/libclient/malikania/client/state/splashscreen_state.cpp	Thu Oct 26 20:03:23 2017 +0200
+++ b/libclient/malikania/client/state/splashscreen_state.cpp	Mon Dec 04 12:17:45 2017 +0100
@@ -41,8 +41,8 @@
     win.clear();
     win.set_drawing_color(foreground_);
     win.draw_text(text_, font_, {
-        (size.width() - clip.width()) / 2,
-        (size.height() - clip.height()) / 2
+        static_cast<int>((size.width() - clip.width()) / 2),
+        static_cast<int>((size.height() - clip.height()) / 2)
     });
     win.present();
 }
--- a/libserver-test/malikania/server/db/test_spell.hpp	Thu Oct 26 20:03:23 2017 +0200
+++ b/libserver-test/malikania/server/db/test_spell.hpp	Mon Dec 04 12:17:45 2017 +0100
@@ -43,18 +43,14 @@
 public:
     class test_dao;
 
-private:
-    test_database& db_;
-
 protected:
     void do_save(std::uint64_t character_id) override;
     void do_remove() override;
     void do_set_level(std::uint8_t level) override;
 
 public:
-    inline test_spell(std::string classname, test_database& db) noexcept
+    inline test_spell(std::string classname, test_database&) noexcept
         : spell(std::move(classname))
-        , db_(db)
     {
     }
 
@@ -75,12 +71,8 @@
 };
 
 class test_spell::test_dao {
-private:
-    test_database& db_;
-
 public:
-    inline test_dao(test_database& db) noexcept
-        : db_(db)
+    inline test_dao(test_database&) noexcept
     {
     }