diff options
author | FearlessTobi <thm.frey@gmail.com> | 2022-07-06 02:20:39 +0200 |
---|---|---|
committer | FearlessTobi <thm.frey@gmail.com> | 2022-07-25 21:57:14 +0200 |
commit | dcfe0a5febb252e3a4f40c1b25765740a269467f (patch) | |
tree | 3f06aa974d4bfba52df45697070ef112b701054b /src/network/network.cpp | |
parent | Merge pull request #8564 from lat9nq/dinner-fork (diff) | |
download | yuzu-dcfe0a5febb252e3a4f40c1b25765740a269467f.tar yuzu-dcfe0a5febb252e3a4f40c1b25765740a269467f.tar.gz yuzu-dcfe0a5febb252e3a4f40c1b25765740a269467f.tar.bz2 yuzu-dcfe0a5febb252e3a4f40c1b25765740a269467f.tar.lz yuzu-dcfe0a5febb252e3a4f40c1b25765740a269467f.tar.xz yuzu-dcfe0a5febb252e3a4f40c1b25765740a269467f.tar.zst yuzu-dcfe0a5febb252e3a4f40c1b25765740a269467f.zip |
Diffstat (limited to '')
-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 |