-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared_state.cpp
43 lines (36 loc) · 911 Bytes
/
shared_state.cpp
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
//
// Copyright (c) 2018 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/vinniefalco/CppCon2018
//
#include "shared_state.hpp"
#include "websocket_session.hpp"
shared_state::
shared_state(std::string doc_root, std::shared_ptr<game> gameInstance)
: doc_root_(std::move(doc_root)),
gameInstance_(std::move(gameInstance))
{
}
void
shared_state::
join(websocket_session& session)
{
sessions_.insert(&session);
}
void
shared_state::
leave(websocket_session& session)
{
sessions_.erase(&session);
}
void
shared_state::
send(std::string message)
{
auto const ss = std::make_shared<std::string const>(std::move(message));
for(auto session : sessions_)
session->send(ss);
}