The Battle for Wesnoth  1.17.0-dev
lobby_data.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
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 <ctime>
19 #include <set>
20 #include <deque>
21 #include <functional>
22 #include <vector>
23 #include <string>
24 
25 class config;
26 
27 namespace mp {
28 
29 /** This class represents a single stored chat message */
31 {
32  /** Create a chat message */
33  chat_message(const std::time_t& timestamp,
34  const std::string& user,
35  const std::string& message);
36 
37  std::time_t timestamp;
38  std::string user;
39  std::string message;
40 };
41 
42 /** this class memorizes a chat session. */
44 {
45 public:
46  chat_session();
47 
48  void add_message(const std::time_t& timestamp,
49  const std::string& user,
50  const std::string& message);
51 
52  void add_message(const std::string& user, const std::string& message);
53 
54  const std::deque<chat_message>& history() const
55  {
56  return history_;
57  }
58 
59  void clear();
60 
61 private:
62  std::deque<chat_message> history_;
63 };
64 
65 /**
66  * This class represents the information a client has about a room
67  */
68 class room_info
69 {
70 public:
71  explicit room_info(const std::string& name);
72 
73  const std::string& name() const
74  {
75  return name_;
76  }
77  const std::set<std::string>& members() const
78  {
79  return members_;
80  }
81  bool is_member(const std::string& user) const;
82  void add_member(const std::string& user);
83  void remove_member(const std::string& user);
84  void process_room_members(const config& data);
85 
86  const chat_session& log() const
87  {
88  return log_;
89  }
91  {
92  return log_;
93  }
94 
95 private:
96  std::string name_;
97  std::set<std::string> members_;
99 };
100 
101 
102 /**
103  * This class represents the information a client has about another player
104  */
105 struct user_info
106 {
107  explicit user_info(const config& c);
108 
109  void update_state(int selected_game_id);
110 
111  void update_relation();
112 
113  enum class user_relation {
114  ME,
115  FRIEND,
116  NEUTRAL,
117  IGNORED
118  };
119 
120  enum class user_state {
121  LOBBY,
122  GAME,
123  SEL_GAME
124  };
125 
126  bool operator<(const user_info& b) const;
127 
128  std::string name;
129  int forum_id;
130  int game_id;
134  bool observing;
135  bool moderator;
136 };
137 
138 /**
139  * This class represents the info a client has about a game on the server
140  */
141 struct game_info
142 {
143  game_info(const config& c, const std::vector<std::string>& installed_addons);
144 
145  bool can_join() const;
146  bool can_observe() const;
147 
148  int id;
149  std::string map_data;
150  std::string name;
151  std::string scenario;
152  std::string type_marker;
154  std::string map_info;
155  std::string map_size_info;
156  std::string era;
157 
158  /** List of modification names and whether they're installed or not. */
159  std::vector<std::pair<std::string, bool>> mod_info;
160 
161  std::string gold;
162  std::string support;
163  std::string xp;
164  std::string vision;
165  std::string status; // vacant slots or turn info
166  std::string time_limit;
167  std::size_t vacant_slots;
168 
169  unsigned int current_turn;
170  bool reloaded;
171  bool started;
172  bool fog;
173  bool shroud;
174  bool observers;
178  bool verified;
180  bool have_era;
182 
185 
186  enum class disp_status {
187  CLEAN,
188  NEW,
189  UPDATED,
190  DELETED
191  };
192 
194 
195  enum class addon_req { SATISFIED, NEED_DOWNLOAD, CANNOT_SATISFY };
196 
197  struct required_addon {
198  std::string addon_id;
200  std::string message;
201  };
202 
203  std::vector<required_addon> required_addons;
205 
206  addon_req check_addon_version_compatibility(const config& local_item, const config& game);
207 
208  const char* display_status_string() const;
209 
210  bool match_string_filter(const std::string& filter) const;
211 };
212 
213 }
std::string scenario
Definition: lobby_data.hpp:151
std::string map_size_info
Definition: lobby_data.hpp:155
std::string status
Definition: lobby_data.hpp:165
std::vector< std::pair< std::string, bool > > mod_info
List of modification names and whether they&#39;re installed or not.
Definition: lobby_data.hpp:159
unsigned int current_turn
Definition: lobby_data.hpp:169
std::deque< chat_message > history_
Definition: lobby_data.hpp:62
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:141
user_state state
Definition: lobby_data.hpp:132
addon_req addons_outcome
Definition: lobby_data.hpp:204
std::time_t timestamp
Definition: lobby_data.hpp:37
std::set< std::string > members_
Definition: lobby_data.hpp:97
std::string user
Definition: lobby_data.hpp:38
void clear(const std::string &key)
Definition: general.cpp:186
const std::deque< chat_message > & history() const
Definition: lobby_data.hpp:54
std::string map_info
Definition: lobby_data.hpp:154
bool remote_scenario
Definition: lobby_data.hpp:153
const chat_session & log() const
Definition: lobby_data.hpp:86
this class memorizes a chat session.
Definition: lobby_data.hpp:43
std::string name
Definition: lobby_data.hpp:150
std::string time_limit
Definition: lobby_data.hpp:166
#define b
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:52
bool password_required
Definition: lobby_data.hpp:179
std::string support
Definition: lobby_data.hpp:162
chat_message(const std::time_t &timestamp, const std::string &user, const std::string &message)
Create a chat message.
Definition: lobby_data.cpp:54
chat_session log_
Definition: lobby_data.hpp:98
std::string name_
Definition: lobby_data.hpp:96
std::string vision
Definition: lobby_data.hpp:164
disp_status display_status
Definition: lobby_data.hpp:193
std::string map_data
Definition: lobby_data.hpp:149
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition: manager.cpp:178
std::string gold
Definition: lobby_data.hpp:161
bool use_map_settings
Definition: lobby_data.hpp:176
std::string name
Definition: lobby_data.hpp:128
static bool operator<(const placing_info &a, const placing_info &b)
Definition: game_state.cpp:140
std::string type_marker
Definition: lobby_data.hpp:152
This class represents the information a client has about a room.
Definition: lobby_data.hpp:68
std::string era
Definition: lobby_data.hpp:156
This class represents the information a client has about another player.
Definition: lobby_data.hpp:105
std::string message
Definition: lobby_data.hpp:39
std::size_t vacant_slots
Definition: lobby_data.hpp:167
std::vector< required_addon > required_addons
Definition: lobby_data.hpp:203
user_relation relation
Definition: lobby_data.hpp:131
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
mock_char c
const std::set< std::string > & members() const
Definition: lobby_data.hpp:77
This class represents a single stored chat message.
Definition: lobby_data.hpp:30
chat_session & log()
Definition: lobby_data.hpp:90
std::string xp
Definition: lobby_data.hpp:163
const std::string & name() const
Definition: lobby_data.hpp:73