The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
player_connection.hpp
Go to the documentation of this file.
1 /* $Id$ */
2 /*
3  Copyright (C) 2016 by Sergey Popov <[email protected]>
4  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #ifndef SERVER_PLAYER_CONNECTION_HPP_INCLUDED
17 #define SERVER_PLAYER_CONNECTION_HPP_INCLUDED
18 
19 #include "simple_wml.hpp"
20 #include "player.hpp"
21 
22 #ifndef _WIN32
23 #define BOOST_ASIO_DISABLE_THREADS
24 #endif
25 #include <boost/asio.hpp>
26 #include <boost/shared_ptr.hpp>
27 
28 #include <boost/multi_index_container.hpp>
29 #include <boost/multi_index/member.hpp>
30 #include <boost/multi_index/mem_fun.hpp>
31 #include <boost/multi_index/ordered_index.hpp>
32 #include <boost/multi_index/hashed_index.hpp>
33 
34 namespace wesnothd
35 {
36 
38 
40 {
41  const socket_ptr socket_;
42  mutable player player_;
44 
45  public:
46 
47  const socket_ptr socket() const { return socket_; }
48  player& info() const { return player_; }
49  const std::string& name() const { return player_.name(); }
50  const boost::shared_ptr<game> get_game() const;
52  int game_id() const;
54  static void enter_lobby(player_record&);
55 
56  player_record(const socket_ptr socket, const player& player) : socket_(socket), player_(player) {}
57 };
58 
59 struct socket_t{};
60 struct name_t{};
61 struct game_t{};
62 
63 using namespace boost::multi_index;
64 
65 typedef multi_index_container<
67  indexed_by<
68  ordered_unique<
69  tag<socket_t>, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record,const socket_ptr,socket)>,
70  hashed_unique<
71  tag<name_t>, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record,const std::string&,name)>,
72  ordered_non_unique<
73  tag<game_t>, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record,int,game_id)>
74  >
76 
77 void send_to_player(socket_ptr socket, simple_wml::document& doc);
78 
79 template<typename Container>
80 void send_to_players(simple_wml::document& data, const Container& players, socket_ptr exclude = socket_ptr())
81 {
82  typename Container::const_iterator iter = players.begin(), iter_end = players.end();
83  for(;iter != iter_end; ++iter)
84  if(*iter != exclude)
85  send_to_player(*iter, data);
86 }
87 
88 void send_server_message(socket_ptr socket, const std::string& message);
89 
90 std::string client_address(socket_ptr socket);
91 
92 } // namespace wesnothd
93 
94 #endif
static void enter_lobby(player_record &)
const socket_ptr socket() const
boost::shared_ptr< game > game_
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
const std::string & name() const
Definition: player.hpp:51
static void set_game(player_record &, boost::shared_ptr< game >)
void send_to_player(socket_ptr socket, simple_wml::document &doc)
Definition: server.cpp:1846
std::string client_address(socket_ptr socket)
Definition: server.cpp:108
const boost::shared_ptr< game > get_game() const
player_record(const socket_ptr socket, const player &player)
multi_index_container< player_record, indexed_by< ordered_unique< tag< socket_t >, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record, const socket_ptr, socket)>, hashed_unique< tag< name_t >, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record, const std::string &, name)>, ordered_non_unique< tag< game_t >, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record, int, game_id)> >> player_connections
GLuint const GLchar * name
Definition: glew.h:1782
const std::string & name() const
Definition: ban.cpp:28
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
boost::shared_ptr< boost::asio::ip::tcp::socket > socket_ptr
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void send_server_message(socket_ptr socket, const std::string &message)
Definition: server.cpp:1873
void send_to_players(simple_wml::document &data, const Container &players, socket_ptr exclude=socket_ptr())