The Battle for Wesnoth  1.15.0-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,
109  const room_info* current_room = nullptr);
110  void update_relation();
111 
113  ME,
116  IGNORED
117  };
118  enum user_state {
122  SEL_GAME
123  };
124 
125  bool operator<(const user_info& b) const;
126 
127  std::string name;
128  int game_id;
132  bool observing;
133 };
134 
135 /**
136  * This class represents the info a client has about a game on the server
137  */
138 struct game_info
139 {
140  game_info(const config& c, const std::vector<std::string>& installed_addons);
141 
142  bool can_join() const;
143  bool can_observe() const;
144 
145  int id;
146  std::string map_data;
147  std::string name;
148  std::string scenario;
150  std::string map_info;
151  std::string map_size_info;
152  std::string era;
153  std::string era_short;
154 
155  /** List of modification names and whether they're installed or not. */
156  std::vector<std::pair<std::string, bool>> mod_info;
157 
158  std::string gold;
159  std::string support;
160  std::string xp;
161  std::string vision;
162  std::string status; // vacant slots or turn info
163  std::string time_limit;
164  std::size_t vacant_slots;
165 
166  unsigned int current_turn;
167  bool reloaded;
168  bool started;
169  bool fog;
170  bool shroud;
171  bool observers;
175  bool verified;
177  bool have_era;
179 
182 
187  DELETED
188  };
190 
191  enum ADDON_REQ { SATISFIED, NEED_DOWNLOAD, CANNOT_SATISFY };
192 
193  struct required_addon {
194  std::string addon_id;
196  std::string message;
197  };
198 
199  std::vector<required_addon> required_addons;
201 
202  ADDON_REQ check_addon_version_compatibility(const config& local_item, const config& game);
203 
204  const char* display_status_string() const;
205 
206  bool match_string_filter(const std::string& filter) const;
207 };
208 
209 }
std::string scenario
Definition: lobby_data.hpp:148
std::string map_size_info
Definition: lobby_data.hpp:151
ADDON_REQ addons_outcome
Definition: lobby_data.hpp:200
std::string status
Definition: lobby_data.hpp:162
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:156
unsigned int current_turn
Definition: lobby_data.hpp:166
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:138
user_state state
Definition: lobby_data.hpp:130
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:205
const std::deque< chat_message > & history() const
Definition: lobby_data.hpp:53
std::string map_info
Definition: lobby_data.hpp:150
bool remote_scenario
Definition: lobby_data.hpp:149
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:147
std::string time_limit
Definition: lobby_data.hpp:163
#define b
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:49
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
bool password_required
Definition: lobby_data.hpp:176
std::string support
Definition: lobby_data.hpp:159
chat_message(const std::time_t &timestamp, const std::string &user, const std::string &message)
Create a chat message.
Definition: lobby_data.cpp:51
chat_session log_
Definition: lobby_data.hpp:97
std::string name_
Definition: lobby_data.hpp:95
std::string vision
Definition: lobby_data.hpp:161
std::string map_data
Definition: lobby_data.hpp:146
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition: manager.cpp:147
std::string gold
Definition: lobby_data.hpp:158
std::string era_short
Definition: lobby_data.hpp:153
bool registered_users_only
Definition: lobby_data.hpp:174
bool use_map_settings
Definition: lobby_data.hpp:173
std::string name
Definition: lobby_data.hpp:127
static bool operator<(const placing_info &a, const placing_info &b)
Definition: game_state.cpp:138
This class represents the information a client has about a room.
Definition: lobby_data.hpp:67
std::string era
Definition: lobby_data.hpp:152
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:164
game_display_status display_status
Definition: lobby_data.hpp:189
std::vector< required_addon > required_addons
Definition: lobby_data.hpp:199
user_relation relation
Definition: lobby_data.hpp:129
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
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:160
const std::string & name() const
Definition: lobby_data.hpp:72