From 6a2dcc8b3d4ed0940e33d60fee701bcdb063eb6b Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Mon, 25 Jul 2022 17:08:20 +0200 Subject: [PATCH] network, yuzu: Improve variable naming and style consistency --- src/common/announce_multiplayer_room.h | 2 +- src/network/network.cpp | 28 +++++++++++++------------- src/network/network.h | 4 ++-- src/network/room.cpp | 16 +++++++-------- src/network/room_member.cpp | 6 ++++-- src/network/verify_user.cpp | 2 +- src/network/verify_user.h | 6 +++--- src/web_service/announce_room_json.cpp | 4 ++-- src/web_service/verify_user_jwt.cpp | 4 ++-- src/web_service/verify_user_jwt.h | 2 +- src/yuzu/multiplayer/host_room.cpp | 2 +- src/yuzu/multiplayer/lobby.cpp | 8 ++++---- src/yuzu/multiplayer/lobby_p.h | 4 ++-- src/yuzu/multiplayer/state.cpp | 12 +++++++---- 14 files changed, 53 insertions(+), 47 deletions(-) diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h index a9e2f89b7a..11a80aa8ee 100644 --- a/src/common/announce_multiplayer_room.h +++ b/src/common/announce_multiplayer_room.h @@ -43,7 +43,7 @@ struct Room { RoomInformation information; std::string id; - std::string verify_UID; ///< UID used for verification + std::string verify_uid; ///< UID used for verification std::string ip; u32 net_version; bool has_password; diff --git a/src/network/network.cpp b/src/network/network.cpp index e1401a4031..36b70c36f2 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -10,8 +10,8 @@ namespace Network { RoomNetwork::RoomNetwork() { - g_room = std::make_shared(); - g_room_member = std::make_shared(); + m_room = std::make_shared(); + m_room_member = std::make_shared(); } bool RoomNetwork::Init() { @@ -19,30 +19,30 @@ bool RoomNetwork::Init() { LOG_ERROR(Network, "Error initalizing ENet"); return false; } - g_room = std::make_shared(); - g_room_member = std::make_shared(); + m_room = std::make_shared(); + m_room_member = std::make_shared(); LOG_DEBUG(Network, "initialized OK"); return true; } std::weak_ptr RoomNetwork::GetRoom() { - return g_room; + return m_room; } std::weak_ptr RoomNetwork::GetRoomMember() { - return g_room_member; + return m_room_member; } void RoomNetwork::Shutdown() { - if (g_room_member) { - if (g_room_member->IsConnected()) - g_room_member->Leave(); - g_room_member.reset(); + if (m_room_member) { + if (m_room_member->IsConnected()) + m_room_member->Leave(); + m_room_member.reset(); } - if (g_room) { - if (g_room->GetState() == Room::State::Open) - g_room->Destroy(); - g_room.reset(); + if (m_room) { + if (m_room->GetState() == Room::State::Open) + m_room->Destroy(); + m_room.reset(); } enet_deinitialize(); LOG_DEBUG(Network, "shutdown OK"); diff --git a/src/network/network.h b/src/network/network.h index 74eb42bf5c..a38f040293 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -27,8 +27,8 @@ public: void Shutdown(); private: - std::shared_ptr g_room_member; ///< RoomMember (Client) for network games - std::shared_ptr g_room; ///< Room (Server) for network games + std::shared_ptr m_room_member; ///< RoomMember (Client) for network games + std::shared_ptr m_room; ///< Room (Server) for network games }; } // namespace Network diff --git a/src/network/room.cpp b/src/network/room.cpp index 22491b2996..b22c5fb89c 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp @@ -29,8 +29,8 @@ public: std::atomic state{State::Closed}; ///< Current state of the room. RoomInformation room_information; ///< Information about this room. - std::string verify_UID; ///< A GUID which may be used for verfication. - mutable std::mutex verify_UID_mutex; ///< Mutex for verify_UID + std::string verify_uid; ///< A GUID which may be used for verfication. + mutable std::mutex verify_uid_mutex; ///< Mutex for verify_uid 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::lock_guard lock(verify_UID_mutex); - uid = verify_UID; + std::lock_guard lock(verify_uid_mutex); + uid = verify_uid; } member.user_data = verify_backend->LoadUserData(uid, token); @@ -1056,8 +1056,8 @@ const RoomInformation& Room::GetRoomInformation() const { } std::string Room::GetVerifyUID() const { - std::lock_guard lock(room_impl->verify_UID_mutex); - return room_impl->verify_UID; + std::lock_guard lock(room_impl->verify_uid_mutex); + return room_impl->verify_uid; } Room::BanList Room::GetBanList() const { @@ -1086,8 +1086,8 @@ bool Room::HasPassword() const { } void Room::SetVerifyUID(const std::string& uid) { - std::lock_guard lock(room_impl->verify_UID_mutex); - room_impl->verify_UID = uid; + std::lock_guard lock(room_impl->verify_uid_mutex); + room_impl->verify_uid = uid; } void Room::Destroy() { diff --git a/src/network/room_member.cpp b/src/network/room_member.cpp index 11a2e276ea..d8cb327210 100644 --- a/src/network/room_member.cpp +++ b/src/network/room_member.cpp @@ -416,8 +416,9 @@ void RoomMember::RoomMemberImpl::Disconnect() { room_information.member_slots = 0; room_information.name.clear(); - if (!server) + if (!server) { return; + } enet_peer_disconnect(server, 0); ENetEvent event; @@ -483,8 +484,9 @@ template void RoomMember::RoomMemberImpl::Invoke(const T& data) { std::lock_guard lock(callback_mutex); CallbackSet callback_set = callbacks.Get(); - for (auto const& callback : callback_set) + for (auto const& callback : callback_set) { (*callback)(data); + } } template diff --git a/src/network/verify_user.cpp b/src/network/verify_user.cpp index d9d98e4955..51094e9bc4 100644 --- a/src/network/verify_user.cpp +++ b/src/network/verify_user.cpp @@ -10,7 +10,7 @@ Backend::~Backend() = 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) { return {}; } diff --git a/src/network/verify_user.h b/src/network/verify_user.h index 5c3852d4aa..ddae67e99a 100644 --- a/src/network/verify_user.h +++ b/src/network/verify_user.h @@ -25,11 +25,11 @@ public: /** * 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 * 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: ~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 diff --git a/src/web_service/announce_room_json.cpp b/src/web_service/announce_room_json.cpp index 082bebaa92..0aae8e2155 100644 --- a/src/web_service/announce_room_json.cpp +++ b/src/web_service/announce_room_json.cpp @@ -54,7 +54,7 @@ static void to_json(nlohmann::json& json, const Room& room) { } static void from_json(const nlohmann::json& json, Room& room) { - room.verify_UID = json.at("externalGuid").get(); + room.verify_uid = json.at("externalGuid").get(); room.ip = json.at("address").get(); room.information.name = json.at("name").get(); try { @@ -116,7 +116,7 @@ WebService::WebResult RoomJson::Register() { auto reply_json = nlohmann::json::parse(result.returned_data); room = reply_json.get(); room_id = reply_json.at("id").get(); - return WebService::WebResult{WebService::WebResult::Code::Success, "", room.verify_UID}; + return WebService::WebResult{WebService::WebResult::Code::Success, "", room.verify_uid}; } void RoomJson::ClearPlayers() { diff --git a/src/web_service/verify_user_jwt.cpp b/src/web_service/verify_user_jwt.cpp index 3133dcbe26..2f294d378a 100644 --- a/src/web_service/verify_user_jwt.cpp +++ b/src/web_service/verify_user_jwt.cpp @@ -35,9 +35,9 @@ std::string GetPublicKey(const std::string& 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 audience = fmt::format("external-{}", verify_UID); + const std::string audience = fmt::format("external-{}", verify_uid); using namespace jwt::params; std::error_code error; auto decoded = diff --git a/src/web_service/verify_user_jwt.h b/src/web_service/verify_user_jwt.h index 6db74c2089..ec3cc29043 100644 --- a/src/web_service/verify_user_jwt.h +++ b/src/web_service/verify_user_jwt.h @@ -17,7 +17,7 @@ public: VerifyUserJWT(const std::string& host); ~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; private: diff --git a/src/yuzu/multiplayer/host_room.cpp b/src/yuzu/multiplayer/host_room.cpp index a48077544d..f59c6a28d5 100644 --- a/src/yuzu/multiplayer/host_room.cpp +++ b/src/yuzu/multiplayer/host_room.cpp @@ -163,7 +163,7 @@ void HostRoomWindow::Host() { // Start the announce session if they chose Public if (is_public) { 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(); if (result.result_code != WebService::WebResult::Code::Success) { QMessageBox::warning( diff --git a/src/yuzu/multiplayer/lobby.cpp b/src/yuzu/multiplayer/lobby.cpp index 0c6648ab5d..6daef97129 100644 --- a/src/yuzu/multiplayer/lobby.cpp +++ b/src/yuzu/multiplayer/lobby.cpp @@ -149,11 +149,11 @@ void Lobby::OnJoinRoom(const QModelIndex& source) { const std::string ip = proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString(); 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(); // attempt to connect in a different thread - QFuture f = QtConcurrent::run([nickname, ip, port, password, verify_UID, this] { + QFuture f = QtConcurrent::run([nickname, ip, port, password, verify_uid, this] { std::string token; #ifdef ENABLE_WEB_SERVICE 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(), Settings::values.yuzu_username.GetValue(), Settings::values.yuzu_token.GetValue()); - token = client.GetExternalJWT(verify_UID).returned_data; + token = client.GetExternalJWT(verify_uid).returned_data; if (token.empty()) { LOG_ERROR(WebService, "Could not get external JWT, verification may fail"); } else { @@ -239,7 +239,7 @@ void Lobby::OnRefreshLobby() { smdh_icon), new LobbyItemHost(QString::fromStdString(room.information.host_username), QString::fromStdString(room.ip), room.information.port, - QString::fromStdString(room.verify_UID)), + QString::fromStdString(room.verify_uid)), new LobbyItemMemberList(members, room.information.member_slots), }); model->appendRow(row); diff --git a/src/yuzu/multiplayer/lobby_p.h b/src/yuzu/multiplayer/lobby_p.h index afb8b99dc0..bb2de4af31 100644 --- a/src/yuzu/multiplayer/lobby_p.h +++ b/src/yuzu/multiplayer/lobby_p.h @@ -123,11 +123,11 @@ public: static const int HostVerifyUIDRole = Qt::UserRole + 4; 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(ip, HostIPRole); setData(port, HostPortRole); - setData(verify_UID, HostVerifyUIDRole); + setData(verify_uid, HostVerifyUIDRole); } QVariant data(int role) const override { diff --git a/src/yuzu/multiplayer/state.cpp b/src/yuzu/multiplayer/state.cpp index de25225dda..661a32b3e5 100644 --- a/src/yuzu/multiplayer/state.cpp +++ b/src/yuzu/multiplayer/state.cpp @@ -98,14 +98,18 @@ void MultiplayerState::retranslateUi() { status_text->setText(tr("Not Connected")); } - if (lobby) + if (lobby) { lobby->RetranslateUi(); - if (host_room) + } + if (host_room) { host_room->RetranslateUi(); - if (client_room) + } + if (client_room) { client_room->RetranslateUi(); - if (direct_connect) + } + if (direct_connect) { direct_connect->RetranslateUi(); + } } void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& state) {