diff options
| author | 2017-07-07 21:34:15 +0200 | |
|---|---|---|
| committer | 2017-07-07 15:34:15 -0400 | |
| commit | 2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8 (patch) | |
| tree | b5298b3c528d9acc1f3fa48f19c9f9c19c97d036 /src/network/room.cpp | |
| parent | Merge pull request #2814 from Kloen/macro-remove (diff) | |
| download | yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.tar.gz yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.tar.xz yuzu-2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8.zip | |
Implement basic virtual Room support based on enet (#2803)
* Added support for network with ENet lib,
connecting is possible, but data can't be sent, yet.
* fixup! Added support for network with ENet lib,
* fixup! CLang
* fixup! Added support for network with ENet lib,
* fixup! Added support for network with ENet lib,
* fixup! Clang format
* More fixups!
* Moved ENetHost* and ENetPeer* into pimpl classes
* fixup! Moved ENetHost* and ENetPeer* into pimpl classes
* fixup! Clang again
* fixup! Moved ENetHost* and ENetPeer* into pimpl classes
* fixup! Moved ENetHost* and ENetPeer* into pimpl classes
* fixup! Moved ENetHost* and ENetPeer* into pimpl classes
Diffstat (limited to 'src/network/room.cpp')
| -rw-r--r-- | src/network/room.cpp | 60 |
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 | |||
| 8 | namespace Network { | ||
| 9 | |||
| 10 | /// Maximum number of concurrent connections allowed to this room. | ||
| 11 | static constexpr u32 MaxConcurrentConnections = 10; | ||
| 12 | |||
| 13 | class Room::RoomImpl { | ||
| 14 | public: | ||
| 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 | |||
| 21 | Room::Room() : room_impl{std::make_unique<RoomImpl>()} {} | ||
| 22 | |||
| 23 | Room::~Room() = default; | ||
| 24 | |||
| 25 | void 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 | |||
| 41 | Room::State Room::GetState() const { | ||
| 42 | return room_impl->state; | ||
| 43 | } | ||
| 44 | |||
| 45 | const RoomInformation& Room::GetRoomInformation() const { | ||
| 46 | return room_impl->room_information; | ||
| 47 | } | ||
| 48 | |||
| 49 | void 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 | ||