diff options
author | B3n30 <bene_thomas@web.de> | 2017-07-07 21:34:15 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2017-07-07 21:34:15 +0200 |
commit | 2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8 (patch) | |
tree | b5298b3c528d9acc1f3fa48f19c9f9c19c97d036 /src/network/network.cpp | |
parent | Merge pull request #2814 from Kloen/macro-remove (diff) | |
download | yuzu-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/network.cpp')
-rw-r--r-- | src/network/network.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp new file mode 100644 index 000000000..51b5d6a9f --- /dev/null +++ b/src/network/network.cpp @@ -0,0 +1,50 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" +#include "common/logging/log.h" +#include "enet/enet.h" +#include "network/network.h" + +namespace Network { + +static std::shared_ptr<RoomMember> g_room_member; ///< RoomMember (Client) for network games +static std::shared_ptr<Room> g_room; ///< Room (Server) for network games +// TODO(B3N30): Put these globals into a networking class + +bool Init() { + if (enet_initialize() != 0) { + LOG_ERROR(Network, "Error initalizing ENet"); + return false; + } + g_room = std::make_shared<Room>(); + g_room_member = std::make_shared<RoomMember>(); + LOG_DEBUG(Network, "initialized OK"); + return true; +} + +std::weak_ptr<Room> GetRoom() { + return g_room; +} + +std::weak_ptr<RoomMember> GetRoomMember() { + return g_room_member; +} + +void Shutdown() { + if (g_room_member) { + if (g_room_member->IsConnected()) + g_room_member->Leave(); + g_room_member.reset(); + } + if (g_room) { + if (g_room->GetState() == Room::State::Open) + g_room->Destroy(); + g_room.reset(); + } + enet_deinitialize(); + LOG_DEBUG(Network, "shutdown OK"); +} + +} // namespace Network |