summaryrefslogtreecommitdiffstats
path: root/src/network/room.cpp
diff options
context:
space:
mode:
authorB3n30 <bene_thomas@web.de>2017-07-07 21:34:15 +0200
committerbunnei <bunneidev@gmail.com>2017-07-07 21:34:15 +0200
commit2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8 (patch)
treeb5298b3c528d9acc1f3fa48f19c9f9c19c97d036 /src/network/room.cpp
parentMerge pull request #2814 from Kloen/macro-remove (diff)
downloadyuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.tar
yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.tar.gz
yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.tar.bz2
yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.tar.lz
yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.tar.xz
yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.tar.zst
yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.zip
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 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "enet/enet.h"
+#include "network/room.h"
+
+namespace Network {
+
+/// Maximum number of concurrent connections allowed to this room.
+static constexpr u32 MaxConcurrentConnections = 10;
+
+class Room::RoomImpl {
+public:
+ ENetHost* server = nullptr; ///< Network interface.
+
+ std::atomic<State> state{State::Closed}; ///< Current state of the room.
+ RoomInformation room_information; ///< Information about this room.
+};
+
+Room::Room() : room_impl{std::make_unique<RoomImpl>()} {}
+
+Room::~Room() = default;
+
+void Room::Create(const std::string& name, const std::string& server_address, u16 server_port) {
+ ENetAddress address;
+ address.host = ENET_HOST_ANY;
+ enet_address_set_host(&address, server_address.c_str());
+ address.port = server_port;
+
+ room_impl->server = enet_host_create(&address, MaxConcurrentConnections, NumChannels, 0, 0);
+ // TODO(B3N30): Allow specifying the maximum number of concurrent connections.
+ room_impl->state = State::Open;
+
+ room_impl->room_information.name = name;
+ room_impl->room_information.member_slots = MaxConcurrentConnections;
+
+ // TODO(B3N30): Start the receiving thread
+}
+
+Room::State Room::GetState() const {
+ return room_impl->state;
+}
+
+const RoomInformation& Room::GetRoomInformation() const {
+ return room_impl->room_information;
+}
+
+void Room::Destroy() {
+ room_impl->state = State::Closed;
+ // TODO(B3n30): Join the receiving thread
+
+ if (room_impl->server) {
+ enet_host_destroy(room_impl->server);
+ }
+ room_impl->room_information = {};
+ room_impl->server = nullptr;
+}
+
+} // namespace Network