summaryrefslogtreecommitdiff
path: root/src/network/room.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/room.cpp')
-rw-r--r--src/network/room.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/network/room.cpp b/src/network/room.cpp
new file mode 100644
index 000000000..48de2f5cb
--- /dev/null
+++ b/src/network/room.cpp
@@ -0,0 +1,60 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "enet/enet.h"
6#include "network/room.h"
7
8namespace Network {
9
10/// Maximum number of concurrent connections allowed to this room.
11static constexpr u32 MaxConcurrentConnections = 10;
12
13class Room::RoomImpl {
14public:
15 ENetHost* server = nullptr; ///< Network interface.
16
17 std::atomic<State> state{State::Closed}; ///< Current state of the room.
18 RoomInformation room_information; ///< Information about this room.
19};
20
21Room::Room() : room_impl{std::make_unique<RoomImpl>()} {}
22
23Room::~Room() = default;
24
25void Room::Create(const std::string& name, const std::string& server_address, u16 server_port) {
26 ENetAddress address;
27 address.host = ENET_HOST_ANY;
28 enet_address_set_host(&address, server_address.c_str());
29 address.port = server_port;
30
31 room_impl->server = enet_host_create(&address, MaxConcurrentConnections, NumChannels, 0, 0);
32 // TODO(B3N30): Allow specifying the maximum number of concurrent connections.
33 room_impl->state = State::Open;
34
35 room_impl->room_information.name = name;
36 room_impl->room_information.member_slots = MaxConcurrentConnections;
37
38 // TODO(B3N30): Start the receiving thread
39}
40
41Room::State Room::GetState() const {
42 return room_impl->state;
43}
44
45const RoomInformation& Room::GetRoomInformation() const {
46 return room_impl->room_information;
47}
48
49void Room::Destroy() {
50 room_impl->state = State::Closed;
51 // TODO(B3n30): Join the receiving thread
52
53 if (room_impl->server) {
54 enet_host_destroy(room_impl->server);
55 }
56 room_impl->room_information = {};
57 room_impl->server = nullptr;
58}
59
60} // namespace Network