diff --git a/src/server/player_connection.cpp b/src/server/player_connection.cpp index cbef0cbfa29d..0d565b3c3e74 100644 --- a/src/server/player_connection.cpp +++ b/src/server/player_connection.cpp @@ -1,23 +1,23 @@ /* - Copyright (C) 2016 - 2018 by Sergey Popov - Part of the Battle for Wesnoth Project https://www.wesnoth.org/ + Copyright (C) 2016 - 2018 by Sergey Popov + Part of the Battle for Wesnoth Project https://www.wesnoth.org/ - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. - See the COPYING file for more details. + See the COPYING file for more details. */ #include "server/player_connection.hpp" + #include "server/game.hpp" namespace wesnothd { - const std::shared_ptr player_record::get_game() const { return game_; @@ -33,14 +33,14 @@ int player_record::game_id() const return game_ ? game_->id() : 0; } -void player_record::set_game(player_record& record, std::shared_ptr new_game) +void player_record::set_game(std::shared_ptr new_game) { - record.game_ = new_game; + game_ = new_game; } -void player_record::enter_lobby(player_record& record) +void player_record::enter_lobby() { - record.game_.reset(); + game_.reset(); } } diff --git a/src/server/player_connection.hpp b/src/server/player_connection.hpp index 3f2dff8c4698..3485a39b9df0 100644 --- a/src/server/player_connection.hpp +++ b/src/server/player_connection.hpp @@ -14,63 +14,84 @@ #pragma once -#include "simple_wml.hpp" -#include "player.hpp" -#include "server_base.hpp" +#include "server/player.hpp" +#include "server/server_base.hpp" +#include "server/simple_wml.hpp" #ifndef _WIN32 -#define BOOST_ASIO_DISABLE_THREADS +#define BOOST_ASIO_DISABLE_THREADS #endif #include -#include -#include +#include #include +#include #include -#include +#include namespace wesnothd { - class player_record { - const socket_ptr socket_; - mutable player player_; - std::shared_ptr game_; - - std::string ip_address; +public: + player_record(const socket_ptr socket, const player& player) + : socket_(socket) + , player_(player) + , game_() + , ip_address(client_address(socket)) + { + } + + const socket_ptr socket() const + { + return socket_; + } + + std::string saved_client_ip() const + { + return ip_address; + } + + player& info() const + { + return player_; + } + + const std::string& name() const + { + return player_.name(); + } - public: - - const socket_ptr socket() const { return socket_; } - std::string saved_client_ip() const { return ip_address; } - player& info() const { return player_; } - const std::string& name() const { return player_.name(); } const std::shared_ptr get_game() const; + std::shared_ptr& get_game(); + int game_id() const; - static void set_game(player_record&, std::shared_ptr); - static void enter_lobby(player_record&); - player_record(const socket_ptr socket, const player& player) : socket_(socket), player_(player), ip_address(client_address(socket)) {} + void set_game(std::shared_ptr new_game); + + void enter_lobby(); + +private: + const socket_ptr socket_; + mutable player player_; + std::shared_ptr game_; + std::string ip_address; }; -struct socket_t{}; -struct name_t{}; -struct game_t{}; - -using namespace boost::multi_index; - -typedef multi_index_container< - player_record, - indexed_by< - ordered_unique< - tag, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record,const socket_ptr,socket)>, - hashed_unique< - tag, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record,const std::string&,name)>, - ordered_non_unique< - tag, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record,int,game_id)> - > -> player_connections; +struct socket_t {}; +struct name_t {}; +struct game_t {}; + +namespace bmi = boost::multi_index; + +using player_connections = bmi::multi_index_container, + bmi::const_mem_fun>, + bmi::hashed_unique, + bmi::const_mem_fun>, + bmi::ordered_non_unique, + bmi::const_mem_fun> +>>; } // namespace wesnothd diff --git a/src/server/server.cpp b/src/server/server.cpp index a92b90b94846..8006c4a3f0ba 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -1724,7 +1724,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr().modify(it, player_record::enter_lobby); + player_connections_.get().modify(it, std::bind(&player_record::enter_lobby, _1)); } // send users in the game a notification to leave the game since it has ended