The Battle for Wesnoth  1.15.12+dev
lobby_data.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
3  Part of the Battle for Wesnoth Project https://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 <ctime>
18 #include <set>
19 #include <deque>
20 #include <functional>
21 #include <vector>
22 #include <string>
23 
24 class config;
25 
26 namespace mp {
27 
28 /** This class represents a single stored chat message */
30 {
31  /** Create a chat message */
32  chat_message(const std::time_t& timestamp,
33  const std::string& user,
34  const std::string& message);
35 
36  std::time_t timestamp;
37  std::string user;
38  std::string message;
39 };
40 
41 /** this class memorizes a chat session. */
43 {
44 public:
45  chat_session();
46 
47  void add_message(const std::time_t& timestamp,
48  const std::string& user,
49  const std::string& message);
50 
51  void add_message(const std::string& user, const std::string& message);
52 
53  const std::deque<chat_message>& history() const
54  {
55  return history_;
56  }
57 
58  void clear();
59 
60 private:
61  std::deque<chat_message> history_;
62 };
63 
64 /**
65  * This class represents the information a client has about a room
66  */
67 class room_info
68 {
69 public:
70  explicit room_info(const std::string& name);
71 
72  const std::string& name() const
73  {
74  return name_;
75  }
76  const std::set<std::string>& members() const
77  {
78  return members_;
79  }
80  bool is_member(const std::string& user) const;
81  void add_member(const std::string& user);
82  void remove_member(const std::string& user);
83  void process_room_members(const config& data);
84 
85  const chat_session& log() const
86  {
87  return log_;
88  }
90  {
91  return log_;
92  }
93 
94 private:
95  std::string name_;
96  std::set<std::string> members_;
98 };
99 
100 
101 /**
102  * This class represents the information a client has about another player
103  */
104 struct user_info
105 {
106  explicit user_info(const config& c);
107 
108  void update_state(int selected_game_id, const room_info* current_room = nullptr);
109 
110  void update_relation();
111 
112  enum class user_relation {
113  ME,
114  FRIEND,
115  NEUTRAL,
116  IGNORED
117  };
118 
119  enum class user_state {
120  LOBBY,
121  SEL_ROOM,
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:61
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:36
std::set< std::string > members_
Definition: lobby_data.hpp:96
std::string user
Definition: lobby_data.hpp:37
void clear(const std::string &key)
Definition: general.cpp:203
const std::deque< chat_message > & history() const
Definition: lobby_data.hpp:53
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:85
this class memorizes a chat session.
Definition: lobby_data.hpp:42
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:51
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:53
chat_session log_
Definition: lobby_data.hpp:97
std::string name_
Definition: lobby_data.hpp:95
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:177
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:139
std::string type_marker
Definition: lobby_data.hpp:152
This class represents the information a client has about a room.
Definition: lobby_data.hpp:67
std::string era
Definition: lobby_data.hpp:156
This class represents the information a client has about another player.
Definition: lobby_data.hpp:104
std::string message
Definition: lobby_data.hpp:38
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:59
mock_char c
const std::set< std::string > & members() const
Definition: lobby_data.hpp:76
This class represents a single stored chat message.
Definition: lobby_data.hpp:29
chat_session & log()
Definition: lobby_data.hpp:89
std::string xp
Definition: lobby_data.hpp:163
const std::string & name() const
Definition: lobby_data.hpp:72