The Battle for Wesnoth  1.15.13+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 
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  GAME,
122  SEL_GAME
123  };
124 
125  bool operator<(const user_info& b) const;
126 
127  std::string name;
128  int forum_id;
129  int game_id;
130  user_relation relation;
131  user_state state;
132  bool registered;
133  bool observing;
134  bool moderator;
135 };
136 
137 /**
138  * This class represents the info a client has about a game on the server
139  */
140 struct game_info
141 {
142  game_info(const config& c, const std::vector<std::string>& installed_addons);
143 
144  bool can_join() const;
145  bool can_observe() const;
146 
147  int id;
148  std::string map_data;
149  std::string name;
150  std::string scenario;
151  std::string type_marker;
152  bool remote_scenario;
153  std::string map_info;
154  std::string map_size_info;
155  std::string era;
157  /** List of modification names and whether they're installed or not. */
158  std::vector<std::pair<std::string, bool>> mod_info;
160  std::string gold;
161  std::string support;
162  std::string xp;
163  std::string vision;
164  std::string status; // vacant slots or turn info
165  std::string time_limit;
166  std::size_t vacant_slots;
168  unsigned int current_turn;
169  bool reloaded;
170  bool started;
171  bool fog;
172  bool shroud;
173  bool observers;
176  bool private_replay;
177  bool verified;
178  bool password_required;
179  bool have_era;
180  bool have_all_mods;
182  bool has_friends;
183  bool has_ignored;
185  enum class disp_status {
186  CLEAN,
187  NEW,
188  UPDATED,
189  DELETED
190  };
191 
192  disp_status display_status;
194  enum class addon_req { SATISFIED, NEED_DOWNLOAD, CANNOT_SATISFY };
196  struct required_addon {
197  std::string addon_id;
198  addon_req outcome;
199  std::string message;
200  };
201 
202  std::vector<required_addon> required_addons;
203  addon_req addons_outcome;
205  addon_req check_addon_version_compatibility(const config& local_item, const config& game);
206 
207  const char* display_status_string() const;
208 
209  bool match_string_filter(const std::string& filter) const;
210 };
211 
212 }
std::string era()
Definition: game.cpp:689
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
bool shuffle_sides()
Definition: game.cpp:469
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
const chat_session & log() const
Definition: lobby_data.hpp:85
this class memorizes a chat session.
Definition: lobby_data.hpp:42
#define b
bool fog()
Definition: game.cpp:533
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:51
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::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition: manager.cpp:177
bool shroud()
Definition: game.cpp:543
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:214
static bool operator<(const placing_info &a, const placing_info &b)
Definition: game_state.cpp:139
bool use_map_settings()
Definition: game.cpp:489
This class represents the information a client has about a room.
Definition: lobby_data.hpp:67
This class represents the information a client has about another player.
Definition: lobby_data.hpp:104
std::string message
Definition: lobby_data.hpp:38
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
const std::string & name() const
Definition: lobby_data.hpp:72