The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
lobby_info.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 - 2025
3 by Tomasz Sniatowski <kailoran@gmail.com>
4 Part of the Battle for Wesnoth Project https://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#pragma once
17
18#include "config.hpp"
20
21#include <boost/dynamic_bitset.hpp>
22
23
24namespace mp
25{
26/**
27 * This class represents the collective information the client has
28 * about the players and games on the server
29 */
31{
32public:
33 lobby_info();
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 */
49
50 /**
51 * Updates the game pointer list and returns a second stage cleanup function to be
52 * called after any actions have been done using the pointer list.
53 */
54 std::function<void()> begin_state_sync();
55
56 /** Returns the raw game list config data. */
57 const config& gamelist() const
58 {
59 return gamelist_;
60 }
61
62 using game_filter_func = std::function<bool(const game_info&)>;
63
64 /** Adds a new filter function to be considered when @ref apply_game_filter is called. */
66 {
67 game_filters_.push_back(func);
68 }
69
70 /** Clears all game filter functions. */
72 {
73 game_filters_.clear();
74 }
75
76 /** Sets whether the result of each game filter should be inverted. */
77 void set_game_filter_invert(std::function<bool(bool)> value)
78 {
80 }
81
82 /** Returns whether the game would be visible after the game filters are applied */
83 bool is_game_visible(const game_info&);
84
85 /** Generates a new list of games that match the current filter functions and inversion setting. */
86 void apply_game_filter();
87
88 /** Returns info on a game with the given game ID. */
90
91 /** Const overload of @ref get_game_by_id. */
92 const game_info* get_game_by_id(int id) const;
93
94 /** Returns info on the user with the given name, or nullptr if they don't eixst. */
95 user_info* get_user(const std::string& name);
96
97 const std::vector<game_info*>& games() const
98 {
99 return games_;
100 }
101
102 const boost::dynamic_bitset<>& games_visibility() const
103 {
104 return games_visibility_;
105 }
106
107 const std::vector<user_info>& users() const
108 {
109 return users_;
110 }
111
112 std::vector<user_info>& users()
113 {
114 return users_;
115 }
116
118 {
120 }
121
123
124private:
126
127 void process_userlist();
128
129 /**
130 * Generates a new vector of game pointers from the ID/game map.
131 * The games will be referenced in ascending order by ID.
132 */
133 void make_games_vector();
134
135 std::vector<std::string> installed_addons_;
136
138
140
142
143 std::vector<game_info*> games_;
144
145 std::vector<user_info> users_;
146
147 std::vector<game_filter_func> game_filters_;
148
149 std::function<bool(bool)> game_filter_invert_;
150
151 boost::dynamic_bitset<> games_visibility_;
152};
153
167
168void do_notify(notify_mode mode, const std::string& sender = "", const std::string& message = "");
169}
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
This class represents the collective information the client has about the players and games on the se...
std::function< bool(bool)> game_filter_invert_
void add_game_filter(game_filter_func func)
Adds a new filter function to be considered when apply_game_filter is called.
void set_game_filter_invert(std::function< bool(bool)> value)
Sets whether the result of each game filter should be inverted.
void process_userlist()
std::function< bool(const game_info &)> game_filter_func
bool gamelist_initialized_
const std::vector< user_info > & users() const
bool is_game_visible(const game_info &)
Returns whether the game would be visible after the game filters are applied.
void clear_game_filters()
Clears all game filter functions.
const std::vector< game_info * > & games() const
bool process_gamelist_diff_impl(const config &data)
void process_gamelist(const config &data)
Process a full game list.
bool process_gamelist_diff(const config &data)
Process a gamelist diff.
void refresh_installed_addons_cache()
std::function< void()> begin_state_sync()
Updates the game pointer list and returns a second stage cleanup function to be called after any acti...
std::vector< user_info > & users()
const boost::dynamic_bitset & games_visibility() const
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
const config & gamelist() const
Returns the raw game list config data.
bool gamelist_initialized() const
game_info_map games_by_id_
void make_games_vector()
Generates a new vector of game pointers from the ID/game map.
std::vector< user_info > users_
user_info * get_user(const std::string &name)
Returns info on the user with the given name, or nullptr if they don't eixst.
std::vector< game_info * > games_
boost::dynamic_bitset games_visibility_
std::map< int, game_info > game_info_map
void apply_game_filter()
Generates a new list of games that match the current filter functions and inversion setting.
std::vector< game_filter_func > game_filters_
std::vector< std::string > installed_addons_
Definitions for the interface to Wesnoth Markup Language (WML).
Main entry points of multiplayer mode.
void do_notify(notify_mode mode, const std::string &sender, const std::string &message)
notify_mode
std::string_view data
Definition picture.cpp:188
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
Definition sound.cpp:139
This class represents the info a client has about a game on the server.
This class represents the information a client has about another player.