network, yuzu: Improve variable naming and style consistency
This commit is contained in:
parent
6b5667dfa5
commit
6a2dcc8b3d
|
@ -43,7 +43,7 @@ struct Room {
|
||||||
RoomInformation information;
|
RoomInformation information;
|
||||||
|
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string verify_UID; ///< UID used for verification
|
std::string verify_uid; ///< UID used for verification
|
||||||
std::string ip;
|
std::string ip;
|
||||||
u32 net_version;
|
u32 net_version;
|
||||||
bool has_password;
|
bool has_password;
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
namespace Network {
|
namespace Network {
|
||||||
|
|
||||||
RoomNetwork::RoomNetwork() {
|
RoomNetwork::RoomNetwork() {
|
||||||
g_room = std::make_shared<Room>();
|
m_room = std::make_shared<Room>();
|
||||||
g_room_member = std::make_shared<RoomMember>();
|
m_room_member = std::make_shared<RoomMember>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RoomNetwork::Init() {
|
bool RoomNetwork::Init() {
|
||||||
|
@ -19,30 +19,30 @@ bool RoomNetwork::Init() {
|
||||||
LOG_ERROR(Network, "Error initalizing ENet");
|
LOG_ERROR(Network, "Error initalizing ENet");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
g_room = std::make_shared<Room>();
|
m_room = std::make_shared<Room>();
|
||||||
g_room_member = std::make_shared<RoomMember>();
|
m_room_member = std::make_shared<RoomMember>();
|
||||||
LOG_DEBUG(Network, "initialized OK");
|
LOG_DEBUG(Network, "initialized OK");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::weak_ptr<Room> RoomNetwork::GetRoom() {
|
std::weak_ptr<Room> RoomNetwork::GetRoom() {
|
||||||
return g_room;
|
return m_room;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::weak_ptr<RoomMember> RoomNetwork::GetRoomMember() {
|
std::weak_ptr<RoomMember> RoomNetwork::GetRoomMember() {
|
||||||
return g_room_member;
|
return m_room_member;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomNetwork::Shutdown() {
|
void RoomNetwork::Shutdown() {
|
||||||
if (g_room_member) {
|
if (m_room_member) {
|
||||||
if (g_room_member->IsConnected())
|
if (m_room_member->IsConnected())
|
||||||
g_room_member->Leave();
|
m_room_member->Leave();
|
||||||
g_room_member.reset();
|
m_room_member.reset();
|
||||||
}
|
}
|
||||||
if (g_room) {
|
if (m_room) {
|
||||||
if (g_room->GetState() == Room::State::Open)
|
if (m_room->GetState() == Room::State::Open)
|
||||||
g_room->Destroy();
|
m_room->Destroy();
|
||||||
g_room.reset();
|
m_room.reset();
|
||||||
}
|
}
|
||||||
enet_deinitialize();
|
enet_deinitialize();
|
||||||
LOG_DEBUG(Network, "shutdown OK");
|
LOG_DEBUG(Network, "shutdown OK");
|
||||||
|
|
|
@ -27,8 +27,8 @@ public:
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<RoomMember> g_room_member; ///< RoomMember (Client) for network games
|
std::shared_ptr<RoomMember> m_room_member; ///< RoomMember (Client) for network games
|
||||||
std::shared_ptr<Room> g_room; ///< Room (Server) for network games
|
std::shared_ptr<Room> m_room; ///< Room (Server) for network games
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Network
|
} // namespace Network
|
||||||
|
|
|
@ -29,8 +29,8 @@ public:
|
||||||
std::atomic<State> state{State::Closed}; ///< Current state of the room.
|
std::atomic<State> state{State::Closed}; ///< Current state of the room.
|
||||||
RoomInformation room_information; ///< Information about this room.
|
RoomInformation room_information; ///< Information about this room.
|
||||||
|
|
||||||
std::string verify_UID; ///< A GUID which may be used for verfication.
|
std::string verify_uid; ///< A GUID which may be used for verfication.
|
||||||
mutable std::mutex verify_UID_mutex; ///< Mutex for verify_UID
|
mutable std::mutex verify_uid_mutex; ///< Mutex for verify_uid
|
||||||
|
|
||||||
std::string password; ///< The password required to connect to this room.
|
std::string password; ///< The password required to connect to this room.
|
||||||
|
|
||||||
|
@ -369,8 +369,8 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
|
||||||
|
|
||||||
std::string uid;
|
std::string uid;
|
||||||
{
|
{
|
||||||
std::lock_guard lock(verify_UID_mutex);
|
std::lock_guard lock(verify_uid_mutex);
|
||||||
uid = verify_UID;
|
uid = verify_uid;
|
||||||
}
|
}
|
||||||
member.user_data = verify_backend->LoadUserData(uid, token);
|
member.user_data = verify_backend->LoadUserData(uid, token);
|
||||||
|
|
||||||
|
@ -1056,8 +1056,8 @@ const RoomInformation& Room::GetRoomInformation() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Room::GetVerifyUID() const {
|
std::string Room::GetVerifyUID() const {
|
||||||
std::lock_guard lock(room_impl->verify_UID_mutex);
|
std::lock_guard lock(room_impl->verify_uid_mutex);
|
||||||
return room_impl->verify_UID;
|
return room_impl->verify_uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Room::BanList Room::GetBanList() const {
|
Room::BanList Room::GetBanList() const {
|
||||||
|
@ -1086,8 +1086,8 @@ bool Room::HasPassword() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Room::SetVerifyUID(const std::string& uid) {
|
void Room::SetVerifyUID(const std::string& uid) {
|
||||||
std::lock_guard lock(room_impl->verify_UID_mutex);
|
std::lock_guard lock(room_impl->verify_uid_mutex);
|
||||||
room_impl->verify_UID = uid;
|
room_impl->verify_uid = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Room::Destroy() {
|
void Room::Destroy() {
|
||||||
|
|
|
@ -416,8 +416,9 @@ void RoomMember::RoomMemberImpl::Disconnect() {
|
||||||
room_information.member_slots = 0;
|
room_information.member_slots = 0;
|
||||||
room_information.name.clear();
|
room_information.name.clear();
|
||||||
|
|
||||||
if (!server)
|
if (!server) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
enet_peer_disconnect(server, 0);
|
enet_peer_disconnect(server, 0);
|
||||||
|
|
||||||
ENetEvent event;
|
ENetEvent event;
|
||||||
|
@ -483,9 +484,10 @@ template <typename T>
|
||||||
void RoomMember::RoomMemberImpl::Invoke(const T& data) {
|
void RoomMember::RoomMemberImpl::Invoke(const T& data) {
|
||||||
std::lock_guard lock(callback_mutex);
|
std::lock_guard lock(callback_mutex);
|
||||||
CallbackSet<T> callback_set = callbacks.Get<T>();
|
CallbackSet<T> callback_set = callbacks.Get<T>();
|
||||||
for (auto const& callback : callback_set)
|
for (auto const& callback : callback_set) {
|
||||||
(*callback)(data);
|
(*callback)(data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
RoomMember::CallbackHandle<T> RoomMember::RoomMemberImpl::Bind(
|
RoomMember::CallbackHandle<T> RoomMember::RoomMemberImpl::Bind(
|
||||||
|
|
|
@ -10,7 +10,7 @@ Backend::~Backend() = default;
|
||||||
|
|
||||||
NullBackend::~NullBackend() = default;
|
NullBackend::~NullBackend() = default;
|
||||||
|
|
||||||
UserData NullBackend::LoadUserData([[maybe_unused]] const std::string& verify_UID,
|
UserData NullBackend::LoadUserData([[maybe_unused]] const std::string& verify_uid,
|
||||||
[[maybe_unused]] const std::string& token) {
|
[[maybe_unused]] const std::string& token) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,11 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies the given token and loads the information into a UserData struct.
|
* Verifies the given token and loads the information into a UserData struct.
|
||||||
* @param verify_UID A GUID that may be used for verification.
|
* @param verify_uid A GUID that may be used for verification.
|
||||||
* @param token A token that contains user data and verification data. The format and content is
|
* @param token A token that contains user data and verification data. The format and content is
|
||||||
* decided by backends.
|
* decided by backends.
|
||||||
*/
|
*/
|
||||||
virtual UserData LoadUserData(const std::string& verify_UID, const std::string& token) = 0;
|
virtual UserData LoadUserData(const std::string& verify_uid, const std::string& token) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +40,7 @@ class NullBackend final : public Backend {
|
||||||
public:
|
public:
|
||||||
~NullBackend();
|
~NullBackend();
|
||||||
|
|
||||||
UserData LoadUserData(const std::string& verify_UID, const std::string& token) override;
|
UserData LoadUserData(const std::string& verify_uid, const std::string& token) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Network::VerifyUser
|
} // namespace Network::VerifyUser
|
||||||
|
|
|
@ -54,7 +54,7 @@ static void to_json(nlohmann::json& json, const Room& room) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void from_json(const nlohmann::json& json, Room& room) {
|
static void from_json(const nlohmann::json& json, Room& room) {
|
||||||
room.verify_UID = json.at("externalGuid").get<std::string>();
|
room.verify_uid = json.at("externalGuid").get<std::string>();
|
||||||
room.ip = json.at("address").get<std::string>();
|
room.ip = json.at("address").get<std::string>();
|
||||||
room.information.name = json.at("name").get<std::string>();
|
room.information.name = json.at("name").get<std::string>();
|
||||||
try {
|
try {
|
||||||
|
@ -116,7 +116,7 @@ WebService::WebResult RoomJson::Register() {
|
||||||
auto reply_json = nlohmann::json::parse(result.returned_data);
|
auto reply_json = nlohmann::json::parse(result.returned_data);
|
||||||
room = reply_json.get<AnnounceMultiplayerRoom::Room>();
|
room = reply_json.get<AnnounceMultiplayerRoom::Room>();
|
||||||
room_id = reply_json.at("id").get<std::string>();
|
room_id = reply_json.at("id").get<std::string>();
|
||||||
return WebService::WebResult{WebService::WebResult::Code::Success, "", room.verify_UID};
|
return WebService::WebResult{WebService::WebResult::Code::Success, "", room.verify_uid};
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomJson::ClearPlayers() {
|
void RoomJson::ClearPlayers() {
|
||||||
|
|
|
@ -35,9 +35,9 @@ std::string GetPublicKey(const std::string& host) {
|
||||||
|
|
||||||
VerifyUserJWT::VerifyUserJWT(const std::string& host) : pub_key(GetPublicKey(host)) {}
|
VerifyUserJWT::VerifyUserJWT(const std::string& host) : pub_key(GetPublicKey(host)) {}
|
||||||
|
|
||||||
Network::VerifyUser::UserData VerifyUserJWT::LoadUserData(const std::string& verify_UID,
|
Network::VerifyUser::UserData VerifyUserJWT::LoadUserData(const std::string& verify_uid,
|
||||||
const std::string& token) {
|
const std::string& token) {
|
||||||
const std::string audience = fmt::format("external-{}", verify_UID);
|
const std::string audience = fmt::format("external-{}", verify_uid);
|
||||||
using namespace jwt::params;
|
using namespace jwt::params;
|
||||||
std::error_code error;
|
std::error_code error;
|
||||||
auto decoded =
|
auto decoded =
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
VerifyUserJWT(const std::string& host);
|
VerifyUserJWT(const std::string& host);
|
||||||
~VerifyUserJWT() = default;
|
~VerifyUserJWT() = default;
|
||||||
|
|
||||||
Network::VerifyUser::UserData LoadUserData(const std::string& verify_UID,
|
Network::VerifyUser::UserData LoadUserData(const std::string& verify_uid,
|
||||||
const std::string& token) override;
|
const std::string& token) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -163,7 +163,7 @@ void HostRoomWindow::Host() {
|
||||||
// Start the announce session if they chose Public
|
// Start the announce session if they chose Public
|
||||||
if (is_public) {
|
if (is_public) {
|
||||||
if (auto session = announce_multiplayer_session.lock()) {
|
if (auto session = announce_multiplayer_session.lock()) {
|
||||||
// Register the room first to ensure verify_UID is present when we connect
|
// Register the room first to ensure verify_uid is present when we connect
|
||||||
WebService::WebResult result = session->Register();
|
WebService::WebResult result = session->Register();
|
||||||
if (result.result_code != WebService::WebResult::Code::Success) {
|
if (result.result_code != WebService::WebResult::Code::Success) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
|
|
|
@ -149,11 +149,11 @@ void Lobby::OnJoinRoom(const QModelIndex& source) {
|
||||||
const std::string ip =
|
const std::string ip =
|
||||||
proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString();
|
proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString();
|
||||||
int port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toInt();
|
int port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toInt();
|
||||||
const std::string verify_UID =
|
const std::string verify_uid =
|
||||||
proxy->data(connection_index, LobbyItemHost::HostVerifyUIDRole).toString().toStdString();
|
proxy->data(connection_index, LobbyItemHost::HostVerifyUIDRole).toString().toStdString();
|
||||||
|
|
||||||
// attempt to connect in a different thread
|
// attempt to connect in a different thread
|
||||||
QFuture<void> f = QtConcurrent::run([nickname, ip, port, password, verify_UID, this] {
|
QFuture<void> f = QtConcurrent::run([nickname, ip, port, password, verify_uid, this] {
|
||||||
std::string token;
|
std::string token;
|
||||||
#ifdef ENABLE_WEB_SERVICE
|
#ifdef ENABLE_WEB_SERVICE
|
||||||
if (!Settings::values.yuzu_username.GetValue().empty() &&
|
if (!Settings::values.yuzu_username.GetValue().empty() &&
|
||||||
|
@ -161,7 +161,7 @@ void Lobby::OnJoinRoom(const QModelIndex& source) {
|
||||||
WebService::Client client(Settings::values.web_api_url.GetValue(),
|
WebService::Client client(Settings::values.web_api_url.GetValue(),
|
||||||
Settings::values.yuzu_username.GetValue(),
|
Settings::values.yuzu_username.GetValue(),
|
||||||
Settings::values.yuzu_token.GetValue());
|
Settings::values.yuzu_token.GetValue());
|
||||||
token = client.GetExternalJWT(verify_UID).returned_data;
|
token = client.GetExternalJWT(verify_uid).returned_data;
|
||||||
if (token.empty()) {
|
if (token.empty()) {
|
||||||
LOG_ERROR(WebService, "Could not get external JWT, verification may fail");
|
LOG_ERROR(WebService, "Could not get external JWT, verification may fail");
|
||||||
} else {
|
} else {
|
||||||
|
@ -239,7 +239,7 @@ void Lobby::OnRefreshLobby() {
|
||||||
smdh_icon),
|
smdh_icon),
|
||||||
new LobbyItemHost(QString::fromStdString(room.information.host_username),
|
new LobbyItemHost(QString::fromStdString(room.information.host_username),
|
||||||
QString::fromStdString(room.ip), room.information.port,
|
QString::fromStdString(room.ip), room.information.port,
|
||||||
QString::fromStdString(room.verify_UID)),
|
QString::fromStdString(room.verify_uid)),
|
||||||
new LobbyItemMemberList(members, room.information.member_slots),
|
new LobbyItemMemberList(members, room.information.member_slots),
|
||||||
});
|
});
|
||||||
model->appendRow(row);
|
model->appendRow(row);
|
||||||
|
|
|
@ -123,11 +123,11 @@ public:
|
||||||
static const int HostVerifyUIDRole = Qt::UserRole + 4;
|
static const int HostVerifyUIDRole = Qt::UserRole + 4;
|
||||||
|
|
||||||
LobbyItemHost() = default;
|
LobbyItemHost() = default;
|
||||||
explicit LobbyItemHost(QString username, QString ip, u16 port, QString verify_UID) {
|
explicit LobbyItemHost(QString username, QString ip, u16 port, QString verify_uid) {
|
||||||
setData(username, HostUsernameRole);
|
setData(username, HostUsernameRole);
|
||||||
setData(ip, HostIPRole);
|
setData(ip, HostIPRole);
|
||||||
setData(port, HostPortRole);
|
setData(port, HostPortRole);
|
||||||
setData(verify_UID, HostVerifyUIDRole);
|
setData(verify_uid, HostVerifyUIDRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant data(int role) const override {
|
QVariant data(int role) const override {
|
||||||
|
|
|
@ -98,15 +98,19 @@ void MultiplayerState::retranslateUi() {
|
||||||
status_text->setText(tr("Not Connected"));
|
status_text->setText(tr("Not Connected"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lobby)
|
if (lobby) {
|
||||||
lobby->RetranslateUi();
|
lobby->RetranslateUi();
|
||||||
if (host_room)
|
}
|
||||||
|
if (host_room) {
|
||||||
host_room->RetranslateUi();
|
host_room->RetranslateUi();
|
||||||
if (client_room)
|
}
|
||||||
|
if (client_room) {
|
||||||
client_room->RetranslateUi();
|
client_room->RetranslateUi();
|
||||||
if (direct_connect)
|
}
|
||||||
|
if (direct_connect) {
|
||||||
direct_connect->RetranslateUi();
|
direct_connect->RetranslateUi();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& state) {
|
void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& state) {
|
||||||
LOG_DEBUG(Frontend, "Network State: {}", Network::GetStateStr(state));
|
LOG_DEBUG(Frontend, "Network State: {}", Network::GetStateStr(state));
|
||||||
|
|
Loading…
Reference in New Issue