2022-07-06 02:20:39 +02:00
|
|
|
// 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 {
|
|
|
|
|
2022-07-22 16:31:13 +02:00
|
|
|
RoomNetwork::RoomNetwork() {
|
|
|
|
g_room = std::make_shared<Room>();
|
|
|
|
g_room_member = std::make_shared<RoomMember>();
|
|
|
|
}
|
2022-07-06 02:20:39 +02:00
|
|
|
|
2022-07-22 16:31:13 +02:00
|
|
|
bool RoomNetwork::Init() {
|
2022-07-06 02:20:39 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-07-22 16:31:13 +02:00
|
|
|
std::weak_ptr<Room> RoomNetwork::GetRoom() {
|
2022-07-06 02:20:39 +02:00
|
|
|
return g_room;
|
|
|
|
}
|
|
|
|
|
2022-07-22 16:31:13 +02:00
|
|
|
std::weak_ptr<RoomMember> RoomNetwork::GetRoomMember() {
|
2022-07-06 02:20:39 +02:00
|
|
|
return g_room_member;
|
|
|
|
}
|
|
|
|
|
2022-07-22 16:31:13 +02:00
|
|
|
void RoomNetwork::Shutdown() {
|
2022-07-06 02:20:39 +02:00
|
|
|
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
|