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 
20 #include <boost/dynamic_bitset.hpp>
21 
22 #include <memory>
23 
24 namespace mp
25 {
26 /**
27  * This class represents the collective information the client has
28  * about the players and games on the server
29  */
31 {
32 public:
33  explicit lobby_info(const config& game_config, const std::vector<std::string>& installed_addons);
34 
35  typedef std::map<int, game_info> game_info_map;
36 
37  /** Process a full game list. Current info is discarded. */
38  void process_gamelist(const config& data);
39 
40  /**
41  * Process a gamelist diff.
42  *
43  * @param data Raw game list data, usually received from the MP server.
44  *
45  * @returns True on success, false on failure (e.g. when the diff did
46  * not apply correctly).
47  */
48  bool process_gamelist_diff(const config& data);
49 
51 
52  /**
53  * Generates a new vector of game pointers from the ID/game map.
54  * The games will be referenced in ascending order by ID.
55  */
56  void make_games_vector();
57 
58  /** Returns the raw game list config data. */
59  const config& gamelist() const
60  {
61  return gamelist_;
62  }
63 
64  using game_filter_func = std::function<bool(const game_info&)>;
65 
66  /** Adds a new filter function to be considered when @ref apply_game_filter is called. */
68  {
69  game_filters_.push_back(func);
70  }
71 
72  /** Clears all game filter functions. */
74  {
75  game_filters_.clear();
76  }
77 
78  /** Sets whether the result of each game filter should be inverted. */
79  void set_game_filter_invert(bool value)
80  {
81  game_filter_invert_ = value;
82  }
83 
84  /** Generates a new list of games that match the current filter functions and inversion setting. */
85  void apply_game_filter();
86 
87  /** Returns info on a game with the given game ID. */
88  game_info* get_game_by_id(int id);
89 
90  /** Const overload of @ref get_game_by_id. */
91  const game_info* get_game_by_id(int id) const;
92 
93  /**
94  * Sorts the user list by the given parameters.
95  *
96  * @param by_name Whether to sort users alphabetically by name.
97  * @param by_relation Whether to sort users by their relation to each other (ie,
98  * display friends before blocked users).
99  */
100  void sort_users(bool by_name, bool by_relation);
101 
102  /** Open a new chat room with the given name. */
103  void open_room(const std::string& name);
104 
105  /** Close the chat room with the given name. */
106  void close_room(const std::string& name);
107 
108  /** Returns whether a room with the given name has been opened. */
109  bool has_room(const std::string& name) const;
110 
111  /** Returns info on room with the given name, or nullptr if it doesn't exist. */
113 
114  /** Const overload of @ref get_room. */
115  const room_info* get_room(const std::string& name) const;
116 
117  /** Returns info on the user with the given name, or nullptr if they don't eixst. */
119 
121  {
122  return whispers_[name];
123  }
124 
125  void update_user_statuses(int game_id, const room_info* room);
126 
127  const std::vector<room_info>& rooms() const
128  {
129  return rooms_;
130  }
131 
132  const std::vector<game_info*>& games() const
133  {
134  return games_;
135  }
136 
137  const boost::dynamic_bitset<>& games_visibility() const
138  {
139  return games_visibility_;
140  }
141 
142  const std::vector<user_info>& users() const
143  {
144  return users_;
145  }
146 
147  const std::vector<user_info*>& users_sorted() const
148  {
149  return users_sorted_;
150  }
151 
152 private:
153  void process_userlist();
154 
156 
157  const std::vector<std::string>& installed_addons_;
158 
160 
162 
163  std::vector<room_info> rooms_;
164 
165  game_info_map games_by_id_;
166 
167  std::vector<game_info*> games_;
168 
169  std::vector<user_info> users_;
170  std::vector<user_info*> users_sorted_;
171 
172  std::map<std::string, chat_session> whispers_;
173 
174  std::vector<game_filter_func> game_filters_;
175 
177 
178  boost::dynamic_bitset<> games_visibility_;
179 };
180 
193 };
194 
195 void do_notify(notify_mode mode, const std::string& sender = "", const std::string& message = "");
196 }
const std::vector< game_info * > & games() const
Definition: lobby_info.hpp:132
const std::vector< user_info > & users() const
Definition: lobby_info.hpp:142
std::vector< char_t > string
user_info * get_user(const std::string &name)
Returns info on the user with the given name, or nullptr if they don't eixst.
Definition: lobby_info.cpp:304
std::map< std::string, chat_session > whispers_
Definition: lobby_info.hpp:172
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:127
std::map< int, game_info > game_info_map
Definition: lobby_info.hpp:35
void update_user_statuses(int game_id, const room_info *room)
Definition: lobby_info.cpp:371
std::vector< room_info > rooms_
Definition: lobby_info.hpp:163
This class represents the collective information the client has about the players and games on the se...
Definition: lobby_info.hpp:30
void add_game_filter(game_filter_func func)
Adds a new filter function to be considered when apply_game_filter is called.
Definition: lobby_info.hpp:67
std::vector< game_filter_func > game_filters_
Definition: lobby_info.hpp:174
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 game list.
Definition: lobby_info.cpp:112
void apply_game_filter()
Generates a new list of games that match the current filter functions and inversion setting...
Definition: lobby_info.cpp:346
bool has_room(const std::string &name) const
Returns whether a room with the given name has been opened.
Definition: lobby_info.cpp:299
room_info * get_room(const std::string &name)
Returns info on room with the given name, or nullptr if it doesn't exist.
Definition: lobby_info.cpp:277
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
Definition: lobby_info.cpp:265
void make_games_vector()
Generates a new vector of game pointers from the ID/game map.
Definition: lobby_info.cpp:331
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:57
const std::vector< user_info * > & users_sorted() const
Definition: lobby_info.hpp:147
const std::vector< std::string > & installed_addons_
Definition: lobby_info.hpp:157
boost::dynamic_bitset games_visibility_
Definition: lobby_info.hpp:178
void sync_games_display_status()
Definition: lobby_info.cpp:244
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)
Sets whether the result of each game filter should be inverted.
Definition: lobby_info.hpp:79
game_info_map games_by_id_
Definition: lobby_info.hpp:165
bool gamelist_initialized_
Definition: lobby_info.hpp:161
Game configuration data as global variables.
Definition: build_info.cpp:53
std::function< bool(const game_info &)> game_filter_func
Definition: lobby_info.hpp:64
std::vector< user_info * > users_sorted_
Definition: lobby_info.hpp:170
This class represents the information a client has about a room.
Definition: lobby_data.hpp:66
bool game_filter_invert_
Definition: lobby_info.hpp:176
void clear_game_filter()
Clears all game filter functions.
Definition: lobby_info.hpp:73
bool process_gamelist_diff(const config &data)
Process a gamelist diff.
Definition: lobby_info.cpp:132
void process_userlist()
Definition: lobby_info.cpp:204
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)
Close the chat room with the given name.
Definition: lobby_info.cpp:322
chat_session & get_whisper_log(const std::string &name)
Definition: lobby_info.hpp:120
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
notify_mode
Definition: lobby_info.hpp:181
const config & game_config_
Definition: lobby_info.hpp:155
void sort_users(bool by_name, bool by_relation)
Sorts the user list by the given parameters.
Definition: lobby_info.cpp:378
void open_room(const std::string &name)
Open a new chat room with the given name.
Definition: lobby_info.cpp:315
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:137
std::vector< user_info > users_
Definition: lobby_info.hpp:169
std::vector< game_info * > games_
Definition: lobby_info.hpp:167
const config & gamelist() const
Returns the raw game list config data.
Definition: lobby_info.hpp:59