The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
data.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Tomasz Sniatowski <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef INC_LOBBY_DATA
16 #define INC_LOBBY_DATA
17 
18 #include "sdl/utils.hpp"
19 
20 #include <set>
21 #include <deque>
22 #include <functional>
23 
24 class config;
25 
26 /** This class represents a single stored chat message */
28 {
29  /** Create a chat message */
30  chat_message(const time_t& timestamp,
31  const std::string& user,
32  const std::string& message);
33 
34  time_t timestamp;
37 };
38 
39 /** this class memorizes a chat session. */
40 class chat_log
41 {
42 public:
43  chat_log();
44 
45  void add_message(const time_t& timestamp,
46  const std::string& user,
47  const std::string& message);
48 
49  void add_message(const std::string& user, const std::string& message);
50 
51  const std::deque<chat_message>& history() const
52  {
53  return history_;
54  }
55 
56  void clear();
57 
58 private:
59  std::deque<chat_message> history_;
60 };
61 
62 /**
63  * This class represents the information a client has about a room
64  */
65 class room_info
66 {
67 public:
68  explicit room_info(const std::string& name);
69 
70  const std::string& name() const
71  {
72  return name_;
73  }
74  const std::set<std::string>& members() const
75  {
76  return members_;
77  }
78  bool is_member(const std::string& user) const;
79  void add_member(const std::string& user);
80  void remove_member(const std::string& user);
81  void process_room_members(const config& data);
82 
83  const chat_log& log() const
84  {
85  return log_;
86  }
88  {
89  return log_;
90  }
91 
92 private:
94  std::set<std::string> members_;
96 };
97 
98 
99 /**
100  * This class represents the information a client has about another player
101  */
102 struct user_info
103 {
104  explicit user_info(const config& c);
105 
106  void update_state(int selected_game_id,
107  const room_info* current_room = nullptr);
108  void update_relation();
109 
112  ME,
115  };
116  enum user_state {
121  };
122 
123  bool operator>(const user_info& b) const;
124 
126  int game_id;
130  bool observing;
131 };
132 
133 /**
134  * This class represents the info a client has about a game on the server
135  */
136 struct game_info
137 {
138  game_info(const config& c, const config& game_config);
139 
140  bool can_join() const;
141  bool can_observe() const;
142 
144  int id;
153 
158  std::string status; // vacant slots or turn info
160  size_t vacant_slots;
161 
162  unsigned int current_turn;
163  bool reloaded;
164  bool started;
165  bool fog;
166  bool shroud;
167  bool observers;
170  bool verified;
172  bool have_era;
174 
177 
183  };
185 
186  const char* display_status_string() const;
187 };
188 
189 class game_filter_base : public std::unary_function<game_info, bool>
190 {
191 public:
193  {
194  }
195  virtual bool match(const game_info& game) const = 0;
196  bool operator()(const game_info& game) const
197  {
198  return match(game);
199  }
200 };
201 
202 template <class T>
204 {
205 public:
206  explicit game_filter_not(const T& t) : t(t)
207  {
208  }
209  bool match(const game_info& game) const
210  {
211  return !t.match(game);
212  }
213  T t;
214 };
215 
217 {
218 public:
220  virtual ~game_filter_stack();
221 
222  /**
223  * Takes ownership
224  */
225  void append(game_filter_base* f);
226 
227  void clear();
228 
229  bool empty() const
230  {
231  return filters_.empty();
232  }
233 
234 protected:
235  std::vector<game_filter_base*> filters_;
236 };
237 
239 {
240 public:
241  bool match(const game_info& game) const;
242 };
243 
244 template <class T, T game_info::*member, class OP = std::equal_to<T> >
246 {
247 public:
248  explicit game_filter_value(const T& value) : member_(member), value_(value)
249  {
250  }
251 
252  bool match(const game_info& game) const
253  {
254  return OP()(game.*member_, value_);
255  }
256 
257 private:
260 };
261 
263 {
264 public:
266  : value_(value)
267  {
268  }
269 
270  bool match(const game_info& game) const;
271 
272 private:
274 };
275 
276 #endif
game_filter_general_string_part(const std::string &value)
Definition: data.hpp:265
std::string name_
Definition: data.hpp:93
std::string status
Definition: data.hpp:158
bool fog
Definition: data.hpp:165
const char * display_status_string() const
Definition: data.cpp:369
void clear()
Definition: data.cpp:404
std::string map_info
Definition: data.hpp:149
bool started
Definition: data.hpp:164
std::vector< game_filter_base * > filters_
Definition: data.hpp:235
This class represents the information a client has about a room.
Definition: data.hpp:65
This class represents a single stored chat message.
Definition: data.hpp:27
this class memorizes a chat session.
Definition: data.hpp:40
const chat_log & log() const
Definition: data.hpp:83
const GLfloat * c
Definition: glew.h:12741
std::string user
Definition: data.hpp:35
time_t timestamp
Definition: data.hpp:34
std::deque< chat_message > history_
Definition: data.hpp:59
std::string gold
Definition: data.hpp:154
const std::string & name() const
Definition: data.hpp:70
std::string time_limit
Definition: data.hpp:159
void clear()
Definition: data.cpp:66
game_filter_value(const T &value)
Definition: data.hpp:248
bool password_required
Definition: data.hpp:171
bool can_observe() const
Definition: data.cpp:363
game_display_status display_status
Definition: data.hpp:184
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
bool shroud
Definition: data.hpp:166
GLdouble GLdouble t
Definition: glew.h:1366
bool has_ignored
Definition: data.hpp:176
This class represents the information a client has about another player.
Definition: data.hpp:102
T game_info::* member_
Definition: data.hpp:258
user_relation relation
Definition: data.hpp:127
std::string vision
Definition: data.hpp:157
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
std::string scenario
Definition: data.hpp:147
game_display_status
Definition: data.hpp:178
bool observers
Definition: data.hpp:167
game_info(const config &c, const config &game_config)
Definition: data.cpp:164
bool match(const game_info &game) const
Definition: data.cpp:423
user_state
Definition: data.hpp:116
bool have_era
Definition: data.hpp:172
std::string map_size_info
Definition: data.hpp:150
user_state state
Definition: data.hpp:128
room_info(const std::string &name)
Definition: data.cpp:71
const std::deque< chat_message > & history() const
Definition: data.hpp:51
GLsizei const GLfloat * value
Definition: glew.h:1817
chat_message(const time_t &timestamp, const std::string &user, const std::string &message)
Create a chat message.
Definition: data.cpp:42
bool match(const game_info &game) const
Definition: data.cpp:413
std::string support
Definition: data.hpp:155
bool empty() const
Definition: data.hpp:229
int game_id
Definition: data.hpp:126
bool have_all_mods
Definition: data.hpp:173
std::string xp
Definition: data.hpp:156
const std::set< std::string > & members() const
Definition: data.hpp:74
bool remote_scenario
Definition: data.hpp:148
bool is_member(const std::string &user) const
Definition: data.cpp:75
std::string map_data
Definition: data.hpp:145
user_relation
Definition: data.hpp:110
size_t vacant_slots
Definition: data.hpp:160
std::string message
Definition: data.hpp:36
virtual ~game_filter_base()
Definition: data.hpp:192
void add_member(const std::string &user)
Definition: data.cpp:80
int id
Definition: data.hpp:144
void add_message(const time_t &timestamp, const std::string &user, const std::string &message)
Definition: data.cpp:53
void update_relation()
Definition: data.cpp:129
bool reloaded
Definition: data.hpp:163
bool registered
Definition: data.hpp:129
Game configuration data as global variables.
Definition: build_info.cpp:38
bool observing
Definition: data.hpp:130
std::string era_short
Definition: data.hpp:152
chat_log()
Definition: data.cpp:49
void append(game_filter_base *f)
Takes ownership.
Definition: data.cpp:399
bool has_friends
Definition: data.hpp:175
bool shuffle_sides
Definition: data.hpp:168
bool match(const game_info &game) const
Definition: data.hpp:209
virtual bool match(const game_info &game) const =0
void process_room_members(const config &data)
Definition: data.cpp:90
GLuint const GLchar * name
Definition: glew.h:1782
std::string name
Definition: data.hpp:125
bool operator>(const user_info &b) const
chat_log & log()
Definition: data.hpp:87
void remove_member(const std::string &user)
Definition: data.cpp:85
bool use_map_settings
Definition: data.hpp:169
std::set< std::string > members_
Definition: data.hpp:94
This class represents the info a client has about a game on the server.
Definition: data.hpp:136
static bool timestamp
Definition: log.cpp:46
surface mini_map
Definition: data.hpp:143
void update_state(int selected_game_id, const room_info *current_room=nullptr)
Definition: data.cpp:110
virtual ~game_filter_stack()
Definition: data.cpp:391
game_filter_not(const T &t)
Definition: data.hpp:206
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
unsigned int current_turn
Definition: data.hpp:162
bool operator()(const game_info &game) const
Definition: data.hpp:196
user_info(const config &c)
Definition: data.cpp:99
bool verified
Definition: data.hpp:170
std::string name
Definition: data.hpp:146
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
bool match(const game_info &game) const
Definition: data.hpp:252
std::string era
Definition: data.hpp:151
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool can_join() const
Definition: data.cpp:358
chat_log log_
Definition: data.hpp:95
GLclampf f
Definition: glew.h:3024