-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
lobby_data.hpp
275 lines (228 loc) · 4.89 KB
/
lobby_data.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
Copyright (C) 2009 - 2014 by Tomasz Sniatowski <kailoran@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef INC_LOBBY_DATA
#define INC_LOBBY_DATA
#include "sdl/utils.hpp"
#include <set>
#include <deque>
#include <functional>
class config;
/** This class represents a single stored chat message */
struct chat_message
{
/** Create a chat message */
chat_message(const time_t& timestamp,
const std::string& user,
const std::string& message);
time_t timestamp;
std::string user;
std::string message;
};
/** this class memorizes a chat session. */
class chat_log
{
public:
chat_log();
void add_message(const time_t& timestamp,
const std::string& user,
const std::string& message);
void add_message(const std::string& user, const std::string& message);
const std::deque<chat_message>& history() const
{
return history_;
}
void clear();
private:
std::deque<chat_message> history_;
};
/**
* This class represents the information a client has about a room
*/
class room_info
{
public:
explicit room_info(const std::string& name);
const std::string& name() const
{
return name_;
}
const std::set<std::string>& members() const
{
return members_;
}
bool is_member(const std::string& user) const;
void add_member(const std::string& user);
void remove_member(const std::string& user);
void process_room_members(const config& data);
const chat_log& log() const
{
return log_;
}
chat_log& log()
{
return log_;
}
private:
std::string name_;
std::set<std::string> members_;
chat_log log_;
};
/**
* This class represents the information a client has about another player
*/
struct user_info
{
explicit user_info(const config& c);
void update_state(int selected_game_id,
const room_info* current_room = NULL);
void update_relation();
enum user_relation {
FRIEND,
ME,
NEUTRAL,
IGNORED
};
enum user_state {
LOBBY,
SEL_ROOM,
GAME,
SEL_GAME
};
bool operator>(const user_info& b) const;
std::string name;
int game_id;
user_relation relation;
user_state state;
bool registered;
bool observing;
};
/**
* This class represents the info a client has about a game on the server
*/
struct game_info
{
game_info(const config& c, const config& game_config);
bool can_join() const;
bool can_observe() const;
surface mini_map;
int id;
std::string map_data;
std::string name;
std::string scenario;
bool remote_scenario;
std::string map_info;
std::string map_size_info;
std::string era;
std::string era_short;
std::string gold;
std::string support;
std::string xp;
std::string vision;
std::string status; // vacant slots or turn info
std::string time_limit;
size_t vacant_slots;
unsigned int current_turn;
bool reloaded;
bool started;
bool fog;
bool shroud;
bool observers;
bool shuffle_sides;
bool use_map_settings;
bool verified;
bool password_required;
bool have_era;
bool has_friends;
bool has_ignored;
enum game_display_status {
CLEAN,
NEW,
UPDATED,
DELETED
};
game_display_status display_status;
const char* display_status_string() const;
};
class game_filter_base : public std::unary_function<game_info, bool>
{
public:
virtual ~game_filter_base()
{
}
virtual bool match(const game_info& game) const = 0;
bool operator()(const game_info& game) const
{
return match(game);
}
};
template <class T>
class game_filter_not : public game_filter_base
{
public:
explicit game_filter_not(const T& t) : t(t)
{
}
bool match(const game_info& game) const
{
return !t.match(game);
}
T t;
};
class game_filter_stack : public game_filter_base
{
public:
game_filter_stack();
virtual ~game_filter_stack();
/**
* Takes ownership
*/
void append(game_filter_base* f);
void clear();
bool empty() const
{
return filters_.empty();
}
protected:
std::vector<game_filter_base*> filters_;
};
class game_filter_and_stack : public game_filter_stack
{
public:
bool match(const game_info& game) const;
};
template <class T, T game_info::*member, class OP = std::equal_to<T> >
class game_filter_value : public game_filter_base
{
public:
explicit game_filter_value(const T& value) : member_(member), value_(value)
{
}
bool match(const game_info& game) const
{
return OP()(game.*member_, value_);
}
private:
T game_info::*member_;
T value_;
};
class game_filter_general_string_part : public game_filter_base
{
public:
explicit game_filter_general_string_part(const std::string& value)
: value_(value)
{
}
bool match(const game_info& game) const;
private:
std::string value_;
};
#endif