-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroom_list.hpp
57 lines (38 loc) · 1.55 KB
/
room_list.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
#pragma once
#include "room.hpp"
#include <boost/uuid.hpp>
#include <chrono>
#include <shared_mutex>
#include <map>
#include <string>
#include <vector>
#include <functional>
#include <memory>
class room_list_t {
public:
using logger = std::function<void(const std::string &)>;
static constexpr size_t name_length = 6; // name is actually a 6-digit number
const logger log_error, log_info;
const std::chrono::minutes lobby_lifetime;
const std::chrono::minutes game_lifetime;
[[nodiscard]] explicit room_list_t(
size_t limit, std::chrono::minutes lobby_lifetime, std::chrono::minutes game_lifetime,
logger log_error = [](const std::string &) {}, logger log_info = [](const std::string &) {}
);
[[nodiscard]] std::shared_ptr<room_t> create(const std::string &version, const room_t::user_t &owner, size_t size);
[[nodiscard]] std::shared_ptr<room_t> get(boost::uuids::uuid id) const;
[[nodiscard]] std::shared_ptr<room_t> get(const std::string &name) const;
[[nodiscard]] bool exists(boost::uuids::uuid id) const;
[[nodiscard]] bool exists(const std::string &name) const;
bool remove(boost::uuids::uuid id);
[[nodiscard]] size_t count() const;
[[nodiscard]] std::vector<std::shared_ptr<room_t>> get_all() const;
[[nodiscard]] size_t get_limit() const;
void set_limit(size_t new_limit);
void clean(std::chrono::milliseconds user_timeout);
protected:
mutable std::shared_mutex rooms_mutex;
size_t limit;
std::map<boost::uuids::uuid, std::shared_ptr<room_t>> rooms;
std::map<std::string, boost::uuids::uuid> name_to_id;
};