The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lobby_info.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2017 by Tomasz Sniatowski <kailoran@gmail.com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "config.hpp"
19 #include <boost/dynamic_bitset.hpp>
20 #include <memory>
21 
22 namespace mp {
23 
24 /**
25  * This class represents the collective information the client has
26  * about the players and games on the server
27  */
29 {
30 public:
31  explicit lobby_info(const config& game_config, const std::vector<std::string>& installed_addons);
32 
33  typedef std::map<int, std::unique_ptr<game_info>> game_info_map;
34 
35  using game_filter_func = std::function<bool(const game_info&)>;
36 
37  /**
38  * Process a full gamelist. Current info is discarded.
39  */
40  void process_gamelist(const config& data);
41 
42  /**
43  * Process a gamelist diff.
44  * @return true on success, false on failure (e.g. when the
45  * diff did not apply correctly)
46  */
47  bool process_gamelist_diff(const config& data);
48 
50 
51  void make_games_vector();
52 
53  const config& gamelist() const
54  {
55  return gamelist_;
56  }
57 
58  void clear_game_filter();
60  void set_game_filter_invert(bool value);
61  void apply_game_filter();
62 
63  game_info* get_game_by_id(int id);
64  const game_info* get_game_by_id(int id) const;
65 
66  void sort_users(bool by_name, bool by_relation);
67 
68  void open_room(const std::string& name);
69  void close_room(const std::string& name);
70  bool has_room(const std::string& name) const;
72  const room_info* get_room(const std::string& name) const;
73 
75 
77 
78  void update_user_statuses(int game_id, const room_info* room);
79 
80  const std::vector<room_info>& rooms() const
81  {
82  return rooms_;
83  }
84  const std::vector<game_info*>& games() const
85  {
86  return games_;
87  }
88  const boost::dynamic_bitset<>& games_visibility() const
89  {
90  return games_visibility_;
91  }
92  const std::vector<game_info*>& games_filtered() const;
93  const std::vector<user_info>& users() const
94  {
95  return users_;
96  }
97  const std::vector<user_info*>& users_sorted() const;
98 
99 private:
100  void process_userlist();
101 
103  const std::vector<std::string>& installed_addons_;
106  std::vector<room_info> rooms_;
107 
108  game_info_map games_by_id_;
109 
110  std::vector<game_info*> games_;
111  std::vector<game_info*> games_filtered_;
112  std::vector<user_info> users_;
113  std::vector<user_info*> users_sorted_;
114  std::map<std::string, chat_session> whispers_;
115  std::vector<game_filter_func> game_filters_;
117  boost::dynamic_bitset<> games_visibility_;
118 };
119 
132 };
133 
134 void do_notify(notify_mode mode, const std::string & sender, const std::string & message);
135 inline void do_notify(notify_mode mode) { do_notify(mode, "", ""); }
136 
137 }
const std::vector< game_info * > & games() const
Definition: lobby_info.hpp:84
const std::vector< user_info > & users() const
Definition: lobby_info.hpp:93
std::vector< char_t > string
user_info * get_user(const std::string &name)
Definition: lobby_info.cpp:293
std::map< std::string, chat_session > whispers_
Definition: lobby_info.hpp:114
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:137
const std::vector< room_info > & rooms() const
Definition: lobby_info.hpp:80
void update_user_statuses(int game_id, const room_info *room)
Definition: lobby_info.cpp:381
std::vector< room_info > rooms_
Definition: lobby_info.hpp:106
This class represents the collective information the client has about the players and games on the se...
Definition: lobby_info.hpp:28
void add_game_filter(game_filter_func func)
Definition: lobby_info.cpp:329
std::vector< game_filter_func > game_filters_
Definition: lobby_info.hpp:115
Definitions for the interface to Wesnoth Markup Language (WML).
this class memorizes a chat session.
Definition: lobby_data.hpp:41
void process_gamelist(const config &data)
Process a full gamelist.
Definition: lobby_info.cpp:114
void apply_game_filter()
Definition: lobby_info.cpp:355
bool has_room(const std::string &name) const
Definition: lobby_info.cpp:288
room_info * get_room(const std::string &name)
Definition: lobby_info.cpp:267
std::vector< game_info * > games_filtered_
Definition: lobby_info.hpp:111
game_info * get_game_by_id(int id)
Definition: lobby_info.cpp:255
void make_games_vector()
Definition: lobby_info.cpp:344
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:48
void do_notify(notify_mode mode, const std::string &sender, const std::string &message)
Definition: lobby_info.cpp:58
const std::vector< std::string > & installed_addons_
Definition: lobby_info.hpp:103
boost::dynamic_bitset games_visibility_
Definition: lobby_info.hpp:117
void sync_games_display_status()
Definition: lobby_info.cpp:235
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition: manager.cpp:148
void set_game_filter_invert(bool value)
Definition: lobby_info.cpp:339
game_info_map games_by_id_
Definition: lobby_info.hpp:108
std::map< int, std::unique_ptr< game_info > > game_info_map
Definition: lobby_info.hpp:33
bool gamelist_initialized_
Definition: lobby_info.hpp:105
Game configuration data as global variables.
Definition: build_info.cpp:53
const std::vector< user_info * > & users_sorted() const
Definition: lobby_info.cpp:405
std::function< bool(const game_info &)> game_filter_func
Definition: lobby_info.hpp:35
std::vector< user_info * > users_sorted_
Definition: lobby_info.hpp:113
This class represents the information a client has about a room.
Definition: lobby_data.hpp:66
bool game_filter_invert_
Definition: lobby_info.hpp:116
chat_session & get_whisper_log(const std::string &name)
Definition: lobby_info.cpp:304
void clear_game_filter()
Definition: lobby_info.cpp:334
bool process_gamelist_diff(const config &data)
Process a gamelist diff.
Definition: lobby_info.cpp:133
const std::vector< game_info * > & games_filtered() const
Definition: lobby_info.cpp:324
void process_userlist()
Definition: lobby_info.cpp:203
This class represents the information a client has about another player.
Definition: lobby_data.hpp:103
lobby_info(const config &game_config, const std::vector< std::string > &installed_addons)
Definition: lobby_info.cpp:40
void close_room(const std::string &name)
Definition: lobby_info.cpp:316
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
notify_mode
Definition: lobby_info.hpp:120
const config & game_config_
Definition: lobby_info.hpp:102
void sort_users(bool by_name, bool by_relation)
Definition: lobby_info.cpp:388
void open_room(const std::string &name)
Definition: lobby_info.cpp:309
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
const boost::dynamic_bitset & games_visibility() const
Definition: lobby_info.hpp:88
std::vector< user_info > users_
Definition: lobby_info.hpp:112
std::vector< game_info * > games_
Definition: lobby_info.hpp:110
const config & gamelist() const
Definition: lobby_info.hpp:53